[1, 2, 3, 2, 5]
From2
When5
If you want to remove, you can implement it with remove all as follows.
List<Integer> list = new ArrayList<>();
list.add(1); list.add(2); list.add(3); list.add(2); list.add(5);
System.out.println(list); //=> [1, 2, 3, 2, 5]
System.out.println(list.removeAll(Arrays.asList(2, 5))); //=> true
System.out.println(list); //=> [1, 3]
list.removeAll(2)You cannot pass elements directly like. (Compile error)
Recommended Posts