字符不会存储在列表中

Oxt*_*tis 4 java arrays list

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)

我让用户输入一个字符串,我想将字符串中的每个单独的字符存储到列表中。

我现在所拥有的并没有正确地做到这一点。我该如何解决这个问题?

Bha*_*ani 5

您可以执行以下操作

String [] myarray = command.split("");
List<String> commandList = Arrays.asList(myarray);  
Run Code Online (Sandbox Code Playgroud)