convert string to arraylist in java

前端 未结 7 956
别跟我提以往
别跟我提以往 2020-12-10 01:03

How to convert a String without separator to an ArrayList.

My String is like this:

String str = \"abcd...\"
         


        
7条回答
  •  伪装坚强ぢ
    2020-12-10 01:37

    Sorry for the Retrobump, but this is now really easy!

    You can do this easily in Java 8 using Streams! Try this:

    String string = "testingString";
    List list = string.chars().mapToObj((i) -> Character.valueOf((char)i)).collect(Collectors.toList());
    System.out.println(list);
    

    You need to use mapToObj because chars() returns an IntStream.

提交回复
热议问题