小编Jav*_*zzs的帖子

通过忽略大小写从列表中删除一个单词

我想ArrayList从给定的字符串中删除单词中所有出现的单词。

我的相框上有3个按钮。一个添加单词,第二个删除单词,第三个显示单词。

我有一个名称为文本框和名称为textvalue数组列表mylist

我用了:

 textValue = text.getText().toLowerCase().trim();
 if (mylist.contains(textValue)) { 
                  mylist.removeAll(Arrays.asList(textValue)); 
                 label.setText("All occurrences of " + textValue + "removed");
                        } else {
                            label.setText("Word not found.");
                        }
Run Code Online (Sandbox Code Playgroud)

如果我举个例子:mark和MARK,它仍然只会删除mark。

我也尝试过:

textValue = text.getText().toLowerCase().trim();
                            for (String current : mylist) {
                                if (current.equalsIgnoreCase(textValue)) {
                                    mylist.removeAll(Collections.singleton(textValue));
                                    label.setText("All occurrences of " + textValue + " removed");
                                } else {
                                    label.setText("Word not found.");
                                }

                            }
Run Code Online (Sandbox Code Playgroud)

java arraylist

3
推荐指数
1
解决办法
68
查看次数

标签 统计

arraylist ×1

java ×1