我想显示 ArrayList
中的所有元素,元素 10(即单词“will”)除外。我该怎么做呢?当我运行下面的代码时,它什么也没显示。
private void practiceButtonActionPerformed(java.awt.event.ActionEvent evt) {
ArrayList <String> practice1 = new ArrayList();
Collections.addAll(practice1, "If", "she", "boarded", "the", "flight"
, "yesterday", "at", "10:00,", "she", "will", "be"
, "here", "anytime", "now.");
contentTextPane.setText(practice1.get(0+1+2+3+4+5+6+7+8+9+11+12+13));
}
最佳答案
您可以像这样删除列表的第 10 个元素:
someList.remove(10);
您可以像这样连接列表的每个元素:
StringBuilder text = new StringBuilder();
for (String thisString : someList) {
text.append(thisString).append(" ");
}
// test it
System.out.println(text.toString());
关于java - 如何显示 ArrayList 中除一个元素以外的所有元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10989941/