List<String> commandList = new ArrayList<String>();
int num = 0;
String command;
command = JOptionPane.showInputDialog(null, "Enter your commands here: ");
while (command.length() > num) {
commandList.add(num, command.substring(num, num+1));
num++;
}
Run Code Online (Sandbox Code Playgroud)
我让用户输入一个字符串,我想将字符串中的每个单独的字符存储到列表中。
我现在所拥有的并没有正确地做到这一点。我该如何解决这个问题?
您可以执行以下操作
String [] myarray = command.split("");
List<String> commandList = Arrays.asList(myarray);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
149 次 |
| 最近记录: |