For the "remove(str, i)" example at 18:58, "k" is a typo, correct is: "str", also, ""v" is a typo, correct is: "i". And then for even more understandability, rename "k1" and 'x' above to "k".
Will there be a variant of "List.of(...)" that provides a regular, mutable ArrayList? Immutability is nice and dandy, but sometimes you just want a plain old list. Or will I have to stick with Guava's "Lists.newArrayList()"?
@@drewcaster Arrays.asList returns an immutable List! You need new ArrayList(Arrays.asList(T... args)) if you actually need a regular mutable ArrayList (without streaming) as OP asked.
Hi, referring the video at 9:33 I tried the below code. List list = Arrays.asList(1,2,3,4,5,6,7,8,9,10); list.removeIf(n -> n==2); However it resulted in the below error. Exception in thread "main" java.lang.UnsupportedOperationException at java.util.AbstractList.remove(AbstractList.java:161) at java.util.AbstractList$Itr.remove(AbstractList.java:374) at java.util.Collection.removeIf(Collection.java:415) Can anyone please tell me what I missed actually?
15:25 Mark makes a small mistake calling it a BiFunction. The foreach actually takes a BiConsumer. That is, consumes two arguments and returns nothing.
A very nice and concise presentation!! Thanks.
Awesome, thanks Stuart mark's,
For the "remove(str, i)" example at 18:58, "k" is a typo, correct is: "str", also, ""v" is a typo, correct is: "i".
And then for even more understandability, rename "k1" and 'x' above to "k".
thanks
Will there be a variant of "List.of(...)" that provides a regular, mutable ArrayList? Immutability is nice and dandy, but sometimes you just want a plain old list. Or will I have to stick with Guava's "Lists.newArrayList()"?
Looks like there's no mutable equivalent according to the API.
Arrays.asList(...) or Stream.of(...) or Arrays.stream(...)
@@drewcaster Arrays.asList returns an immutable List! You need new ArrayList(Arrays.asList(T... args)) if you actually need a regular mutable ArrayList (without streaming) as OP asked.
The Hodor stickers xD
Hi, referring the video at 9:33 I tried the below code.
List list = Arrays.asList(1,2,3,4,5,6,7,8,9,10);
list.removeIf(n -> n==2);
However it resulted in the below error.
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.remove(AbstractList.java:161)
at java.util.AbstractList$Itr.remove(AbstractList.java:374)
at java.util.Collection.removeIf(Collection.java:415)
Can anyone please tell me what I missed actually?
Here is an answer on Stack Overflow.
stackoverflow.com/questions/7885573/remove-on-list-created-by-arrays-aslist-throws-unsupportedoperationexception
Cool.... Thanks Francois Green
15:25 Mark makes a small mistake calling it a BiFunction. The foreach actually takes a BiConsumer. That is, consumes two arguments and returns nothing.