Ade*_*e A 4 java arrays string split
我想将像"我的狗"这样的字符串分成以下数组:
| M | y | space char will be in here | D | o | g |
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
String []in_array;
input = sc.next();
in_array = input.split(""); //Note this there is no delimiter
for(int k=1; k < in_array.length; k++){
System.out.print(" "+in_array[k]);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
它只打印出"我的"
如果您只看到"我的",那就是您在input
字符串中所拥有的一切.你使用Scanner.next()吗?
for(String s : "My dog".split(""))
System.out.println(s);
Run Code Online (Sandbox Code Playgroud)
版画
{empty line}
M
y
d
o
g
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
14129 次 |
最近记录: |