Path equals() method in Java with Examples Last Updated : 16 Jul, 2019 Comments Improve Suggest changes Like Article Like Report The Java Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a directory.path of an entity could be of two types one is an absolute path and other is a relative path. The absolute path is the location address from the root to the entity while the relative path is the location address which is relative to some other path. equals() method of java.nio.file.Path used to compare this path for equality with the passed object as a parameter. If the given object is not a Path or is a Path associated with a different FileSystem, then this method returns false. This method returns true if, and only if, the given object is a Path that is identical to this Path. Syntax: boolean equals(Object other) Parameters: This method accepts a single parameter the other object which is used to be compared. Return value: This method returns true if, and only if, the given object is a Path that is identical to this Path. Below programs illustrate equals() method: Program 1: Java // Java program to demonstrate // java.nio.file.Path.equals() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Paths Path path1 = Paths.get("D:\\eclipse\\configuration" + "\\org.eclipse.update"); Path path2 = Paths.get("D:\\eclipse\\configuration" + "\\org.eclipse.update"); // compare paths for equality boolean response = path1.equals(path2); // print result if (response) System.out.println("Both are equal"); else System.out.println("Both are not equal"); } } Output: Both are equal Program 2: Java // Java program to demonstrate // java.nio.file.Path.equals() method import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; public class GFG { public static void main(String[] args) throws IOException { // create object of Paths Path path1 = Paths.get("D:\\eclipse\\configuration" + "\\org.eclipse.update"); Path path2 = Paths.get("D:\\temp\\Spring"); // compare paths for equality boolean response = path1.equals(path2); // print result if (response) System.out.println("Both are equal"); else System.out.println("Both are not equal"); } } Output: Both are not equal References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#equals() Comment More infoAdvertise with us Next Article Path equals() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java Java-Functions Java-Path java.nio.file package Practice Tags : Java Similar Reads Path endsWith() method in Java with Examples endswith() method of java.nio.file.Path used to check if this path object ends with the given path or string which we passed as parameter. There are two types of endsWith() methods. endsWith(String other) method of java.nio.file.Path used to check if this path ends with a Path, constructed by conver 3 min read Path compareTo() method in Java with Examples The Java Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a di 3 min read Path toUri() method in Java with Examples The toUri() method of java.nio.file.Path interface used to return a URI to represent this path. This method converts this path into an absolute URI with a scheme equal to the URI scheme that identifies the provider. The exact form of the scheme-specific part is highly provider dependent. In the scen 2 min read Static Method in Java With Examples In Java, the static keyword is used to create methods that belongs to the class rather than any specific instance of the class. Any method that uses the static keyword is referred to as a static method.Features of Static Method:A static method in Java is associated with the class, not with any objec 3 min read Path toFile() method in Java with Examples The toFile() method of java.nio.file.Path interface used to return a java.io.File object representing this path object. if this Path is associated with the default provider, then this method returns a java.io.File object constructed with the String representation of this path. If this path was creat 2 min read Java File Class equals() Method with Examples 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 equival 2 min read Path getRoot() method in Java with Examples The Java Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a di 2 min read Path subpath() method in Java with Examples The subpath(int beginIndex, int endIndex) method of java.nio.file.Path used to return a relative Path that is a subsequence of the name elements of this path. We will pass begin and end indexes to construct a subpath. The beginIndex and endIndex parameters specify the subsequence of name elements. T 2 min read Path resolve() method in Java with Examples resolve() method of java.nio.file.Path used to resolve the given path against this path. There are two types of resolve() methods. resolve(String other) method of java.nio.file.Path used to converts a given path string to a Path and resolves it against this Path in the exact same manner as specified 3 min read Path getFileName() method in Java with Examples The Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a directo 2 min read Like