How to use comma and dot as delimiter in addition with Java default delimiter

后端 未结 3 1830
春和景丽
春和景丽 2021-01-14 06:33

I have a text file which contains lot of permutations and combinations of special characters, white space and data. I am storing the content of this file into an array list,

3条回答
  •  情书的邮戳
    2021-01-14 06:48

    You could do this:

    String str = "...";
    List List = Arrays.asList(str.split(","));
    

    Basically the .split() method will split the string according to (in this case) delimiter you are passing and will return an array of strings.

    However, you seem to be after a List of Strings rather than an array, so the array must be turned into a list by using the Arrays.asList() utility. Just as an FYI you could also do something like so:

    String str = "...";
    ArrayList List = Arrays.asList(str.split(","));
    

提交回复
热议问题