Java Path.compareTo(Path other)

Syntax

Path.compareTo(Path other) has the following syntax.

int compareTo(Path other)

Example

In the following code shows how to use Path.compareTo(Path other) method.


import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
//  w  w  w.  j av  a2  s  .c om
public class Main {

    public static void main(String[] args) {

        Path path01 = Paths.get("/tutorial/Java/JavaFX/Topic.txt");
        Path path02 = Paths.get("C:/tutorial/Java/JavaFX/Topic.txt");


        //compare using Path.compareTo
        int compare = path01.compareTo(path02);
        System.out.println(compare);
    }
}

The code above generates the following result.





















Home »
  Java Tutorial »
    java.nio.file »




DirectoryStream.Filter
Files
FileStore
FileSystem
FileVisitor
Path
Paths
WatchService