Path equals() 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 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.
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:
Both are equal
Both are not equal
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.