Stream流

tech2022-08-27  129

#Stream流 总体上包括:生成流  中间操作 终结操作  三部分

##生成流 ###Collection体系 使用stream()方法生成流 ###Map体系 间接生成流 ###数组 使用静态方法of 生成流 ##中间操作 常用的8种 filter 过滤 limit 截取指定参数的数据 skip 跳过指定个数的数据 concat 合并 distinct 取消重复 sorted 排序(两种) map mapToInt ##终结操作 forEach long #stream流的收集 收集的方法:collect 方法中的参数是一个Collector接口 Collectors工具类

//元素收集到List集合中```

在这里插入List<String> names = listStream.collect(Collectors.toList());代码片

//元素收集到Set集合中

Set<Integer> ages = setStream.collect(Collectors.toSet());

//集合中的元素收集到Map集合中

Map<String,Integer> map = arrayStream.collect(Collectors.toMap(s -> s.split(reqex:",")[0],s -> Integer.parseInt(s.split(reqex:",")[1])));

`

最新回复(0)