Java 8 - How to build up a string from initial string with only one traversal

I have an url like: String url = "https://.../foo/a/555/data1";

Goal: Transform the url to the string: a555data1

I want to build this result traversing the string only once.

I decided for the following process:

I want to "stream" the string starting from the back.

If it is not a backslash insert/append at the front of a deque.

If it is the third backslash end

I have successfully written a horrible solution below, can it be made pretty using streams? Gods of StackO heed my call!!!

Deque lifo = new ArrayDeque<>();

int count = 0;

for (int i = testUrl.length() -...

Read More »

By: StackOverFlow - Wednesday, 14 November

Related Posts