How to convert comma-separated String to List?

前端 未结 24 2398
你的背包
你的背包 2020-11-22 16:58

Is there any built-in method in Java which allows us to convert comma separated String to some container (e.g array, List or Vector)? Or do I need to write custom code for t

24条回答
  •  醉酒成梦
    2020-11-22 17:21

    Here is another one for converting CSV to ArrayList:

    String str="string,with,comma";
    ArrayList aList= new ArrayList(Arrays.asList(str.split(",")));
    for(int i=0;i"+aList.get(i));
    }
    

    Prints you

    -->string
    -->with
    -->comma

提交回复
热议问题