How to convert a String into an array of Strings containing one character each

前端 未结 6 909
攒了一身酷
攒了一身酷 2020-12-15 12:13

I have a small problem here.I need to convert a string read from console into each character of string. For example string: \"aabbab\" I want to this string into array of st

6条回答
  •  眼角桃花
    2020-12-15 13:10

    Use toCharArray() method. It splits the string into an array of characters:

    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#toCharArray%28%29

    String str = "aabbab";
    char[] chs = str.toCharArray();
    

提交回复
热议问题