Split individual characters from a string

前端 未结 3 1655
粉色の甜心
粉色の甜心 2020-12-12 05:06

I\'m writing following program to separate characters from a string and assign it to an array.

public class Str {
    public static void main(String[] args)          


        
3条回答
  •  旧时难觅i
    2020-12-12 05:48

    Have you tried the toCharArray() method from the String class.

    The issue with splitting the String with this "" is that "" matches the first character in the string and therefore you get an empty character.

    To verify this claim. You could try str.indexOf(""). This would give you a value 0. If the argument does not occur as a substring, -1 is returned, according to the documentation.

提交回复
热议问题