Arun
Arun

Reputation: 1296

Deduce longest paths

I have a list of Path (java.nio.file).

For example

/a/b/c/d
/a/b/c
/a/b/
/a/x/y/z
/a/x/

Out of these paths I need to retrieve only the longest paths.

For example, /a/b/c/d and /a/x/y/z are the longest paths.

How should I retrieve by using or not using any of the methods in the Path interface in java?

Upvotes: 0

Views: 55

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522752

Try this code:

import java.nio.file.Path;
import java.nio.file.Paths;

public class PathTest {
    public static void main(String[] args) {
        String path = "/a/b/c/d";
        Path p = Paths.get(path);
        int num = p.getNameCount();
        System.out.println(num);  // prints 4
    }
}

Upvotes: 1

Related Questions