Rather than depending on ArrayList.toString()
implementation, you could write a one-liner, if you are using java 8:
String result = sList.stream()
.reduce("", String::concat);
If you prefer using StringBuffer
instead of String since String::concat
has a runtime of O(n^2)
, you could convert every String
to StringBuffer
first.
StringBuffer result = sList.stream()
.map(StringBuffer::new)
.reduce(new StringBuffer(""), StringBuffer::append);