I have String ArrayList has some elements but I need to convert it to string each element is separated from other by - this is the arrayList
List<String> items = new ArrayList<String>();
items.add("a");
items.add("b");
items.add("c");
:
:
I need to get the string like this
"a-b-c-..."
If you are using Java 8 you can use the join
function of the String
class:
String result = String.join("-", items);
If you are programming for Android, Java 8 is not available. You can instead use:
String result = TextUtils.join("-", items);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments