-
Notifications
You must be signed in to change notification settings - Fork 4
Join List Strings with Commas in Java
Ramesh Fadatare edited this page Jul 11, 2019
·
2 revisions
This Java example concatenates elements of a list with commas using String.join() method.
In below example, we are passing a list as an argument to the String.join() method.
```java
import java.util.Arrays;
import java.util.List;
public class Java8StringJoinExample {
public static void main(String[] args) {
List<String> list = Arrays.asList("Today", "i", "am", "going", "to", "office");
String joined = String.join(",", list);
System.out.println(joined);
}
}
Output:
Today,i,am,going,to,office
The elements of the list are joined with a single space character
String joined = String.join(" ", list);