集合變Stream流一行代碼可以做很多事情;
I 可以做過濾
.filter(λ表達式) λ表達式是要return一個 Boolean 的判斷,做過濾
II可以做裁剪 斷尾留頭
.limit(number)
III可以做跳躍 斬頭留尾
skip(number)
IV 去重
.distinct()
List<String> distinctList = Stream.of(listA).flatMap(Collection::stream).distinct().collect(Collectors.toList());
兩個List集合 合並
其實是用兩個Stream 流合並
List<String> collect = Stream.of(listA, listB).flatMap(Collection::stream).distinct().collect(Collectors.toList());
最后
@一個流只能用一次,
@流里面的操作改的只是流里面的數據,原來的數據源沒有改變;