collectingAndThen
有一个List
//得到所有流水号 去重 List
上面的写法会觉得很别扭,看起来不太舒服,大概是不够 ‘’优雅‘’、
找了一种优雅的写法
list = list.stream() .collect( Collectors.collectingAndThen( Collectors.toCollection( () -> new TreeSet<>(Comparator.comparing(da -> da.get("ORDTB407CA00").toString()))),//根据订单号去重 ArrayList::new));
仔细看了一下,发现 collectingAndThen 是先收集结果,然后对收集到的结果做后面 Function 函数的操作
例如下面代码 对收纳的结果进行拼接,然后将拼接结果转大写
String collect = Stream.of("aoe", "uid", "htn").collect(Collectors.collectingAndThen(Collectors.joining("-"), String::toUpperCase));
这个方法本人用的也不是特别多,所以也有一些疑惑的地方,以后会更新