The following code:
public static void main (String [] args) {
// store the list of 0-9
List <Integer> = new new List the ArrayList <> ();
for (int I = 0; I <10; I ++) {
List .add (I);
}
System.out.println ( "original list:");
System.out.println (list);
// filter list even
list = list.stream () filter (a -> a. 2 == 0%) .collect (Collectors.toList ());
System.out.println ( "even list:");
System.out.println (list);
}
the output is:
the original list:
[0 , 1, 2, 3, 4, 5, 6, 7, 8, 9]
in the list even number:
[0, 2, 4, 6, 8]
brief Description of
use filter are: filter (item -> item of Analyzing logic), wherein the filter retains recording determination condition is true
java8 stream filter is simple to use
Guess you like
Origin www.cnblogs.com/zhuyeshen/p/12162601.html
Ranking