Java lambda sublist

What is the shortest way to express "get a new list B from list A, where is the condition" via Java 8 lambda?

Let's say I have List<Integer> a = Arrays.asList(1, 2, 3, 4, 5) , and I need a new List, B, where the value is> 3.

I read the new streaming collections API, but I'm not sure I have found a better way to do this, and I don't want to relax the question with what is probably my less perfect solution.

+6
source share
1 answer
 a.stream().filter(x -> x > 3).collect(Collectors.toList()); 
+14
source

Source: https://habr.com/ru/post/956682/


All Articles