List<String> list = Arrays.asList("foo", "bar", "baz");
String joined = String.join(" and ", list); // "foo and bar and baz"
String result = String.join(",", list);
List<String> list = Arrays.asList("a","b","c");
String result = String.join(",", list);
System.out.println(result); //prints a,b,c
String[] data = { "First", "Second", "Third" };
StringBuilder sb = new StringBuilder();
for (String item : data) {
sb.append(item).append(", ");
}
sb.setLength(sb.length() - 2);
// generates output:
// First, Second, Third