[HD Pg 0, Sec. 14.1.5 - the-removeif-method]
Posted: Thu Sep 09, 2021 2:22 pm
The example in this section gives "UnsupportedOperationException" because lists created with List.Of are unchangeable. Methods such as add or remove cannot be applied. The book says that the display will be [1,3,5].
Example from the book.
"
List<Integer> iList = List.of(1, 2, 3, 4, 5, 6);
Predicate<Integer> p = x->x%2==0;
iList.removeIf(p);
System.out.println(iList);
The above code prints [1, 3, 5] .
"
Example from the book.
"
List<Integer> iList = List.of(1, 2, 3, 4, 5, 6);
Predicate<Integer> p = x->x%2==0;
iList.removeIf(p);
System.out.println(iList);
The above code prints [1, 3, 5] .
"