Java 11 here. I am trying to use org.apache.commons.lang3.StringUtils.join to take a list of strings and join/concatenate them into a single string, separated by an @ sign. If there is only one (1) string in the list, then the joins/concatenated output should be that same string, no delimiter. Hence:
- If inputList string is
[ "Hello", "World" ], output should be"Hello@World" - If inputList string is
[ "Hello" ], output should be"Hello"
My best attempt thus far is:
String output = StringUtils.join("@", inputList);
But for an inputList of [ "Hello", "World" ] this gives me output of:
@[Hello, World]
And for an inputList of [ "Hello" ], this gives me output of:
@[Hello]
Can anyone spot where I'm going awry?
The method itself works, you just need to put in the array first, then the delimiter. In the documentation there is an example, and when I just tried it it worked.
The following code outputs
Hello@World, I just switched the parameters.