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] .
"
[HD Pg 0, Sec. 14.1.5 - the-removeif-method]
Moderator: admin
-
- Posts: 2
- Joined: Thu Sep 09, 2021 2:13 pm
- Contact:
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 0, Sec. 14.1.5 - the-removeif-method]
Which build/version of the book are you seeing this in?
In "Wednesday 21 st October, 2020" Build 2.4, I see a new ArrayList in there. See attached screenshot.
In "Wednesday 21 st October, 2020" Build 2.4, I see a new ArrayList in there. See attached screenshot.
If you like our products and services, please help us by posting your review here.
-
- Posts: 2
- Joined: Thu Sep 09, 2021 2:13 pm
- Contact:
Re: [HD Pg 0, Sec. 14.1.5 - the-removeif-method]
Oh...I'm sorry. It's about 18th Sep 2019 Build 1.7. I did't know it was a new book.
-
- Site Admin
- Posts: 10065
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: [HD Pg 0, Sec. 14.1.5 - the-removeif-method]
No, it is the same book but we try to make best use of the On Demand Publishing model to apply corrections as soon as possible.
If you like our products and services, please help us by posting your review here.
Who is online
Users browsing this forum: No registered users and 107 guests