0

Let's san I have a String looks like

a/b/c/d

I need to process some job(MKCOL) for following values in a row.

a
a/b
a/b/c
a/b/c/d

I know I can split and using them concatenating one by one.

Is there any way to do this with stream?

1 Answer 1

2

Sure it is:

String s = "a/b/c/d";
String[] array = s.split("/");
for (int i = 1; i <= array.length; i++) {
    String part = Arrays.stream(array).limit(i).collect(Collectors.joining("/"));
    System.out.println(part);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.