String.join relies on the StringJoiner class, which itself relies on an internal StringBuilder to create a concatenated string.
So this is very similar to using a StringBuilder and adding to it or using a + chain (which is currently being converted to StringBuilder operations StringBuilder compiler).
But the value of String.join not a general replacement for + or String.concat , but rather as the "reverse operation" of the String.split operation. This makes sense in this context - when you have a bunch of lines that you want to concat with a separator - instead of replacing concat .
That is, to build output like "a/b/c/d" or "(a+b+c+d)" , if the array or list contains a , b , c and d , String.join or StringJoiner will make the operation understandable and readable.
Realskeptic
source share