Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How can I extend(resolve) a Path with a Stream of String

2803364Nov 26 2014 — edited Nov 26 2014

I have following two variables;

final Path root;   // /a/b/c final Stream<String> split; // 'd', 'e', 'f'  Path path;   // /a/b/c/d/e/f

I want to resolve every element in split to the root.

Currently I'm trying to do like this.

// is the final combiner ok? final Path path = split.reduce(root, (p, s) -> p.resolve(s), (p1, p2) -> p1);

Is this the right way? Is there any other way to do this?

Is following code better than the above code?

Path path = root; split.forEach(s -> path = path.resolve(s)); // path must be final?

Thanks.

Comments

Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Dec 24 2014
Added on Nov 26 2014
0 comments
695 views