Java Examples
Java Examples
memu home questions

Populate List With Comma Seperated Sting

This java example shows how populate a list from a string with a comma separated names.

Source: (

import java.util.*;
public class PopulateList {
   public static void main(String[] args) {
      String str = "qqq,www,eee,rrr,ttt,yyy";
      List<String> list = new ArrayList<>();
      System.out.println("String: " + str);
      for (String item: str.split("\\s*,\\s*")) {
      System.out.println("List: " + list);


$ java PopulateList 
String: qqq,www,eee,rrr,ttt,yyy
List: [qqq, www, eee, rrr, ttt, yyy]