我使用这部分代码将 jlist 中的选择项获取到字符串列表中。我得到以下结果:
[[String1, String2, String3,...]]
如何避免双 []?谢谢
static List<String> strlist = new ArrayList<String>();
public class tog {
List<String> strlisttemp = new ArrayList<String>();
final JList list = new JList(strlisttemp.toArray());
list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
final ListSelectionListener listSelectionListener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
String lstr = list.getSelectedValuesList().toString();
System.out.println(lstr);
strlist = Arrays.asList(lstr.split("\\s*,\\s*"));
}
};
list.addListSelectionListener(listSelectionListener);
JOptionPane.showMessageDialog(null, list, "Select", JOptionPane.QUESTION_MESSAGE);
System.out.println(strlist);
}
这是有问题的部分:当我打印 lstr 它工作正常[...]。当我使用这个时:
strlist = Arrays.asList(lstr.split("\\s*,\\s*"));
然后 System.out.println(strlist); 打印双括号