Java collections convert a string to a list of characters

前端 未结 10 1991
礼貌的吻别
礼貌的吻别 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:39

    The lack of a good way to convert between a primitive array and a collection of its corresponding wrapper type is solved by some third party libraries. Guava, a very common one, has a convenience method to do the conversion:

    List characterList = Chars.asList("abc".toCharArray());
    Set characterSet = new HashSet(characterList);
    

提交回复
热议问题