ll = new LinkedList<>();
IntStream.range(0, 100).forEach((i) -> ll.add(i));
ll = ll.stream().filter((i) -> i != 10 )
.collect(Collectors.toCollection(LinkedList::new));
IntStream.range(0, 100).forEach((i) -> ll.add(i));
ll = ll.stream().filter((i) -> i != 10 )
.collect(Collectors.toCollection(LinkedList::new));
The above code is filtering, creating a new list and assigning to an existing list. Instead of creating a new list, list should be filtered in place as below:
ll.removeIf((i)->i == 10);
Comments
Post a Comment