day24-转换算子

// 把数组编程list;
List<String> strings = Arrays.asList("a","b");
Set<String> ss = new HashSet<>(strings);
strings = new ArrayList<String>(ss);
System.out.println(strings);
// 把集合转换为流;
Stream<String> stream = strings.stream();
filter 对元素进行过滤,不符合条件的就不要了;
// 返回true就要,返回false就不要;
// collect把符合条件的转换为集合,属于动作算子(终止操作);
List<String> value = stream.filter(x->x.equals("a")).collect(Collectors.toList);
value.forEach(x->System.out.println(x));
// Stream操作之后必须重新生成,不能重复使用;
// 重新生成流;
stream = strings.stream();
// 跳过一个,就是b 只能有一个动作算子;
value.stream.skip(1).collect(Collectors.toList());
System.out.println(value);
// 再次生成流;
stream = strings.stream();
// map在集合中对数据进行操作,比如修改;
List<Integer> integers = Arrays.alList(100,900,1552,153);
Stream<Integer> stream2 = integers.stream();
List<Integer> value2 = stream2.map(x->x+100).collect(Collectors.toList());
System.out.println(value2);
// 重新生成流;
stream = strings.stream();
// 去重;
value = stream.distinct().collect(Collectors.toList());
System.out.println(value);
// 重新生成流;
stream = strings.stream();
// 取一个集合的前几条数据;
value = stream.skip(1).limit(2).collect(Collectors.toList());
System.out.println(value);
String str = "wwww,,,aaaa,,,sss";
IntStream stream3 = srr.chars();
stream3.distinct().forEach(x->System.out.println(x));
strings = Arrays.asList("1,2","a,b");
stream = strings.stream();
stream.map(x->x.split(",")).flatMap(arr->Arrays.stream(arr)).collect(Collectors.toList);
System.out.println(value);
// 常用的动作算子;
// 循环forEach;
// 收集器collect;
// 结算min,max,count,average;
List<String> strings = Arrays.asList("a","b");
// forEach;
stream.filter(x->x.equals("a")).forEach(x->System.out.println(x));
stream = strings.stream();
// 统计个数;
long count = stream.filter(x->x.equals("a")).count();
System.out.println(count);
stream = strings.stream();
// 收集器,把结果转换为集合;
List<String> value = stream.map(x->x+"--").collect(Collectors.toList());
System.out.println(value);
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卑微-程序员

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值