import java.util.ArrayList;
import java.util.List;
import java.util.Optional; public class Streams1 { public static void main(String[] args) { List<String> stringCollection = new ArrayList<>();
stringCollection.add("ddd2");
stringCollection.add("aaa2");
stringCollection.add("bbb1");
stringCollection.add("aaa1");
stringCollection.add("bbb3");
stringCollection.add("ccc");
stringCollection.add("bbb2");
stringCollection.add("ddd1"); // filtering stringCollection.stream().filter((s) -> s.startsWith("a")).forEach(System.out::println); // "aaa2", "aaa1" // sorting stringCollection
.stream()
.sorted()
.filter((s) -> s.startsWith("a"))
.forEach(System.out::println); // "aaa1", "aaa2" // mapping stringCollection
.stream()
.map(String::toUpperCase)
.sorted((a, b) -> b.compareTo(a))
.forEach(System.out::println); // "DDD2", "DDD1", "CCC", "BBB3", "BBB2", "AAA2", "AAA1" // matching boolean anyStartsWithA = stringCollection
.stream()
.anyMatch((s) -> s.startsWith("a")); System.out.println(anyStartsWithA); // true boolean allStartsWithA = stringCollection
.stream()
.allMatch((s) -> s.startsWith("a")); System.out.println(allStartsWithA); // false boolean noneStartsWithZ = stringCollection
.stream()
.noneMatch((s) -> s.startsWith("z")); System.out.println(noneStartsWithZ); // true // counting long startsWithB = stringCollection
.stream()
.filter((s) -> s.startsWith("b"))
.count(); System.out.println(startsWithB); // 3 // reducing Optional<String> reduced =
stringCollection
.stream()
.sorted()
.reduce((s1, s2) -> s1 + "#" + s2); reduced.ifPresent(System.out::println);
// "aaa1#aaa2#bbb1#bbb2#bbb3#ccc#ddd1#ddd2" } }

最新文章

  1. hduoj 1286 找新朋友
  2. javascript--Object
  3. 将packages/apps/下的app导入eclipse
  4. Wildcard Matching
  5. 以“图片渐入渐出”为例讲述jQuery插件的具体实现
  6. echshop jquery与transpart冲突解决?
  7. asp.net Server.HtmlEncode和HtmlDecode
  8. 初学swift笔记 继承(十)
  9. BZOJ 1385: [Baltic2000]Division expression
  10. python常见的特异点
  11. Activity的切换动画
  12. Flask知识点二
  13. Unity UGUI图文混排源码(一)
  14. azkaban使用
  15. apache2反向代理
  16. putty登陆sourceforge.net(设置登录)
  17. Find the peace with yourself
  18. 早上STO单紧急寻源处理
  19. 【LOJ】#2511. 「BJOI2018」双人猜数游戏
  20. Shell记录-Shell命令(文件查找)

热门文章

  1. PTA(Advanced Level)1033.To Fill or Not to Fill
  2. Nginx部署前后端分离的单页应用配置
  3. python学习-5 python基础-2 条件语句(if的简单用法2---elif)
  4. python中requests库使用方法详解
  5. S02_CH13_ AXI_PWM 实验
  6. Spring实战(四)Spring高级装配中的bean profile
  7. grpc的demo
  8. win10下 安装迅雷精简版
  9. JS 发送弹幕
  10. el表达式获取url中携带的参数