public static void main(String[] args) {
Person[] person= new Person[]{new Person("张三",11),new Person("李四",12)};
//创建方法
//Stream.of(person);
//集合stream
//Intermediate 操作
// map (mapToInt, flatMap 等)、 filter、 distinct、 sorted、 peek、 limit、 skip、 parallel、 sequential、 unordered
//Function super T, ? extends R> mapper 处理T类型数据返回R类型数据
//依旧返回一个stream 筛选
List collect2 = Stream.of(person).filter(p -> p.getAge() > 0).collect(Collectors.toList());
//去重
final Stream distinct = Stream.of(person).distinct();
//排序
Stream.of(person).sorted(Person::compareTo).collect(Collectors.toList());
//这部操作会直接改变 person 的值
System.out.println(Stream.of(person).peek(p-> p.setAge(90)).collect(Collectors.toList()));
//并行的处理
Stream.of(person).parallel();
//串行
Stream.of(person).sequential();
List collect = Stream.of(person).map(Person::initAge).collect(Collectors.toList());
//Terminal 操作
// forEach、 forEachOrdered、 toArray、 reduce、 collect、 min、 max、 count、 anyMatch、 allMatch、 noneMatch、 findFirst、 findAny、 iterator
//循环输出
Stream.of(person).forEach(System.out::println);
//排序加输出
Stream.of(person).forEachOrdered(System.out::println);
Object[] objects = Stream.of(person).toArray();
System.out.println(Arrays.toString(objects));
//直接指定了数据类型
Person[] people = Stream.of(person).toArray(Person[]::new);
System.out.println(Arrays.toString(people));
//归纳 参数为BinaryOperator 方法定义 (acc,item) acc 为上次计算后的结果 item 是当前条目 最后返回的是Optional
//参数为BinaryOperator 继承 BiFunction 方法定义为传入两个参数 返回一个结果
//可以设置初始值
Integer init =20;
Integer red = Stream.of(person).map(Person::getAge).reduce(init, (acc, item) -> {
//做运算的
acc += item;
return acc;
});
System.out.println(red);
//创建 累加 合并
linkedList