也因为我个人是比较喜欢使用lambda和stream新特性的,但是调试“有些困难”,下面介绍idea自带的调试工具

下面的算是流程比较长的了,当然实际工作中可能遇到比这个还要复杂的。

        List<Integer> list = Arrays.asList(45,56,23,89,34,78,56);
        Map<Boolean, List<Integer>> collect = list.stream()
                .filter(i -> i * 2 > 60)
                .sorted()
                .map(i -> i - 10)
                .distinct()
                .collect(Collectors.groupingBy(i -> i >= 50, Collectors.toList()));
        System.out.println(collect);

先在stream那行打上断点。点击debug运行

stream流:idea调试小技巧

再点击那个小按钮

stream流:idea调试小技巧

弹出一个stream trace的框,初始状态如下

stream流:idea调试小技巧

然后我们就能看到每一步的运行情况了。

filter:

stream流:idea调试小技巧

sorted:

stream流:idea调试小技巧

map:

stream流:idea调试小技巧

distinct:

stream流:idea调试小技巧

collect:

stream流:idea调试小技巧

相关文章:

  • 2021-07-07
  • 2021-11-14
  • 2021-07-20
  • 2022-12-23
  • 2021-04-29
  • 2021-10-13
  • 2021-06-30
猜你喜欢
  • 2021-09-15
  • 2021-12-09
  • 2022-01-01
  • 2021-10-27
  • 2021-07-01
相关资源
相似解决方案