Is there a function like join that returns List's data as a string of all the elements, joined by delimiter provided?
List<String> join; .... String join = list.join('+"); // join == "Elem 1+Elem 2";
or one must use an iterator to manually glue the elements?
In Java, we can use String. join(",", list) to join a List String with commas.
If you want to concatenate a list of numbers ( int or float ) into a single string, apply the str() function to each element in the list comprehension to convert numbers to strings, then concatenate them with join() .
Java 8...
String joined = String.join("+", list);
Documentation: http://docs.oracle.com/javase/8/docs/api/java/lang/String.html#join-java.lang.CharSequence-java.lang.Iterable-
You can use the StringUtils.join()
method of Apache Commons Lang:
String join = StringUtils.join(joinList, "+");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With