大文字と小文字を区別を無視して、リストから単語を削除します

Javazzs:

私は、内の単語のすべての出現を削除するArrayList指定した文字列から。

私は私のフレーム上の3つのボタンがあります。単語を追加一、第二、その削除し語、及びショーの単語、第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.");
                        }

私は、例えば置く場合:マークと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.");
                                }

                            }
デッドプール :

ただ、使用removeIfを

mylist.removeIf(value->value.equalsIgnoreCase(textValue));

removeIf受け入れる述語を使用すると、対応する定義されているので、引数としてラムダ式をに一致するすべての値を削除するには、textValue大文字と小文字が区別を無視して

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=330209&siteId=1