1.废话不多说,直接上示例代码,下述的stream流做了过滤,映射和收集操作。
@Test
public void testStream() {
List<PersonInfoEntity> arrayList = new ArrayList<PersonInfoEntity>();
arrayList.add(new PersonInfoEntity("haha01", 20, 180.0));
arrayList.add(new PersonInfoEntity("haha02", 18, 180.0));
arrayList.add(new PersonInfoEntity("haha03", 19, 180.0));
List<Integer> collect =
arrayList.stream()
.filter(x -> x.getAge() > 18)
.map(PersonInfoEntity::getAge)
.collect(Collectors.toList());
System.out.println(collect);
}
2.开始debug调试,在stream流开始打上断点。
3.把鼠标放在如图所指示的位置
显示出英文:Trace Current Stream Chain
意思是 :跟踪当前的Stream流链路
4.点击3中的 Trace Current Stream Chain 图标,出现如下Stream Trace
(1)过滤掉(age)年龄小于等于18岁的数据
(2)映射出每个人的年龄
(3)最后收映射好的数据,放入一个集合容器中去
(4)debug结束