Java File Class equals() Method with Examples Last Updated : 02 Feb, 2022 Comments Improve Suggest changes Like Article Like Report The equals() method of Java File Class compares the pathname supplied in the argument to the pathname provided in the argument. If the parameter is not null and points to the same file or directory, this function returns true. The operating system determines if the two abstract pathnames are equivalent or not. Syntax: public boolean equals(Object obj) Parameters: obj - The item against which the abstract pathname is to be compared Return Value: It returns true, if and only if the items are the same; otherwise, false. Example: Java // Java program to show the usage of // File Class equals() Method import java.io.File; public class Main { public static void main(String[] args) { boolean bool; try { // create new files File f1 = new File("Gfg.txt"); File f2 = f1; File f3 = new File("Gfg2.txt"); // returns boolean value bool = f1.equals(f2); // prints the output System.out.println("Is is equal : " + bool); // returns boolean value bool = f1.equals(f3); // prints the output System.out.print("Is is equal : " + bool); } catch (Exception e) { // if any error occurs e.printStackTrace(); } } } The method compares two File instances to see whether they are the same. This approach does not compare the content of the file or directory; instead, it checks if the pathnames are the same. Output: Comment More infoAdvertise with us Next Article Java File Class equals() Method with Examples S sanketnagare Follow Improve Article Tags : Java Java-Functions Java-File Class Practice Tags : Java Similar Reads Charset equals() method in Java with Examples The equals() method is a built-in method of the java.nio.charset checks if a given object of charset is equal to another given object of the charset. Two charsets are considered equal if, and only if, they have the same canonical names. A charset is never equal to any other type of object. Syntax: p 2 min read Date equals() method in Java with Examples The equals() method of Java Date class checks if two Dates are equal, based on millisecond difference. Syntax: public boolean equals(Object obj) Parameters: The function accepts a single parameter obj which specifies the object to be compared with. Return Value: The function gives 2 return values sp 2 min read Boolean equals() method in Java with examples The equals() method of Boolean class is a built in method of Java which is used check equality of two Boolean object. Syntax: BooleanObject.equals(Object ob) Parameter: It take a parameter ob of type Object as input which is the instance to be compared. Return Type: The return type is boolean. It re 2 min read Field equals() method in Java with Examples The equals() method of java.lang.reflect.Field is used to compare two field objects. This method compares two field objects and returns true if both objects are equal otherwise false. The two Field objects are considered equal if and only if when they were declared by the same class and have the sam 3 min read Double.equals() Method in Java with Examples The Double.equals() in Java is a built-in function from the java.lang.Double class. This method compares the content of two Double objects. The result is true if and only if the argument is not null and is a Double object that contains the same double value as this object. This method is useful for 3 min read Like