什么是 Stream 流式计算
计算都应该交给流来操作!
java.util.stream
// 代码示例
package pers.vincent.matrix.subject.streamdemo;
import java.util.Arrays;
import java.util.List;
public class StreamDemo {
public static void main(String[] args) {
User u1 = new User(1, "a", 12);
User u2 = new User(2, "b", 2);
User u3 = new User(3, "c", 90);
User u4 = new User(4, "d", 8);
User u5 = new User(5, "e", 10);
List<User> userList = Arrays.asList(u1, u2, u3, u4, u5);
// 流式计算范例
userList.stream()
.filter(u->{return u.getId()%2==0;})
.map(u->{return u.getName().toUpperCase();})
.limit(1)
.forEach(System.out::println);
}
}