查看这段代码
String input="I use this method";
String word=input.replaceAll(" ","/");
char buf[]=word.toCharArray();
但我想要另一种方法来做到这一点?
最佳答案
这是我发现的将包含空格的字符串转换为 java 中的 char 数组的最简单方法。
String input = "I use this method";
char[] buf = input.toCharArray();
看起来您做得对,但是使用 replaceAll("", "/") 删除了所有空白
关于java - 如何在java中的char数组中存储带有空格的字符串值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30173506/