java - 如何显示 ArrayList 中除一个元素以外的所有元素?

标签 java arraylist element

我想显示 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/

相关文章:

Java ObjectMapper.readValue 将泛型类型转换为 LinkedHashMap

java - 正则表达式 - 检测特定 URL 并替换该字符串

Java - 列表还是数组?

java - 在java中制作扩展类的数组列表

java - 无法在 Gmail 主页的语言选择器中选择元素

java - H264 字节流到图像文件

java - 避免显式依赖 API 的正确方法,同时仍然使用它(如果存在)

python - 如何计算ndarray中元素的频率

javascript - JavaScript中如何通过ID获取子元素?