Remove all occurrences of an element from ArrayList
arraylist, java
Solution
l.removeAll(Collections.singleton("first"));
Problem
I am using `java.util.ArrayList`, I want to remove all the occurrences of a particular element. ``` List<String> l = new ArrayList<String>(); l.add("first"); l.add("first"); l.add("second"); l.remove("first"); ``` It's removing only the first occurrence. But I want all the occurrences to be removed after `l.remove("first");` I expect list to be left out only with the value "second". I found by googling that it can be achieved by creating new list and calling `list.removeAll(newList)`. But is it possible to remove all occurrences without creating new list or is there any API available to achieve it ?