Force Delete File using Java

To force delete file using Java, we can use the FileUtils or FileDeleteStrategy class available in Apache Commons Io demo to force delete file using java import java.io.File; import java.io.IOException; import org.apache.commons.io.FileUtils; public class ForceDelete { public static void main(String[] args){ File directory = new File(“c:\\directoryname\\filename.txt”); try { FileUtils.forceDelete(directory); System.out.println(“force delete file in java”); } … Read more

Delete File using Java API

Delete file using java with the help of delete method available in java.io.File package. The File.delete() method return boolean value. if the file is deleted successfully then the delete() method return true, on the other hand if it not able to delete file using java then it returns false. below example demonstrates how to delete … Read more

How to Get Min and Max Value of Primitive Data Types in Java

Java consists of eight primitive data types which are byte, short, int, long, float, double, boolean and char. A primitive is named by a reserved keyword and is predefined by the language. Primitive values do not share state with other primitive values. We can get the min and max value of primitive data types using … Read more

Get Current Date and Time in Java

In this post we will see that how to get current date and time in java using the class java.util.Date and java.text.SimpleDateFormat. Below is the code to get current date and time in java using Date class :- import java.text.SimpleDateFormat; import java.util.Date; public class CurrentDate { public static void main(String[] args) { Date dt = … Read more

Detect Duplicates using Set

We can Easily Detect Duplicates using Set. In this tutorial we will create a program whose functionality will be to detect duplicates using set in the given input. in the program we are using Set because set does not contain duplicate elements. code to detect duplicates using set:- import java.util.HashSet; import java.util.Set; public class FindDuplicates … Read more

Different Way to Iterate Over Collection in Java

In java there are multiple ways to iterate, loop through, traverse the elements in collection. For example if you want to display the elements, remove the elements in a given collection then you can implement different ways to iterate, loop or traverse on a given collection like iterator, basic for loop, enhanced for loop etc. … Read more

Efficient Way to Check String is Palindrome or Not

A String can be Palindrome if that reads the same forward or reversed. For example, ‘radar’, ‘level’ , ‘refer’ are some Palindrome words. A String is palindrome or not can be checked using different approaches but the best approach is to compare string first and last character and then proceed further Program to check Palindrome … Read more