Java collections convert a string to a list of characters

前端 未结 10 1990
礼貌的吻别
礼貌的吻别 2020-12-02 12:51

I would like to convert the string containing abc to a list of characters and a hashset of characters. How can I do that in Java ?

List

        
10条回答
  •  渐次进展
    2020-12-02 13:30

    IntStream can be used to access each character and add them to the list.

    String str = "abc";
    List charList = new ArrayList<>();
    IntStream.range(0,str.length()).forEach(i -> charList.add(str.charAt(i)));
    

提交回复
热议问题