Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Convert String into comma separated List in Java
At first, set a list with string values −
List<String> myList = new ArrayList<>(
Arrays.asList("One", "Two", "Three", "Four"));
Now, use String.join() to set them as a comma separated list −
String str = String.join(", ", myList);
Example
Following is the program to convert string into comma separated List in Java −
import java.util.*;
public class Demo {
public static void main(String args[]) {
List<String> myList = new ArrayList<>(Arrays.asList("One", "Two", "Three", "Four"));
System.out.println("List = " + myList);
// comma separated
String str = String.join(", ", myList);
System.out.println("String (Comma Separated) = " + str);
}
}
Output
List = [One, Two, Three, Four] Comma separated String: One, Two, Three, Four
Advertisements
