单词转换大写
wordList.stream().map(String::toUpperCase).collect(Collectors.toList());
平方数
numList.stream().map(n -> n * n).collect(Collectors.toList());
合并数组
Stream.of( Arrays.asList(1), Arrays.asList(2, 3), Arrays.asList(4, 5, 6) ).flatMap((childList) -> childList.stream());
留下偶数
numList.filter(n -> n%2 == 0).toArray(Integer[]::new);
字符串连接
Stream.of("A", "B", "C", "D").reduce("", String::concat);
最小值
Stream.of(1, 2, 3).reduce(Double.MAX_VALUE, Double::min);
求和(有初始值)
Stream.of(1, 2, 3).reduce(0, Integer::sum);
limit取前N个
Stream.of(1, 2, 3).limit(2).collect(Collectors.toList());
仍掉N个
Stream.of(1, 2, 3).skip(1).collect(Collectors.toList());
排序
Stream.of(1, 2, 3).limit(2).sorted((p1, p2) -> p1>p2)).collect(Collectors.toList());
找出最长一行的长度
newBufferedReader(newFileReader(log)).lines().mapToInt(String::length).max().getAsInt();
生成一个等差数列
Stream.iterate(0, n -> n + 3).forEach(x -> System.out.print(x + " "))