Streadm常见使用
https://www.javazhiyin.com/62590.html
这篇文章讲解了Stream流水线的基本使用,我会在博客中实现文中的代码
package com.cd.stream;
import java.util.stream.Stream;
/**
* @author Chen zhi xiang
* @date 2020/6/16 15:21
*/
public class StreamDemo {
public static void main(String[] args) {
//全变大写
Stream.of("apple","orange").map(e->e.toUpperCase())
.forEach(System.out::println);
//输出单词的长度
Stream.of("apple","orange").map(e->e.length())
.forEach(System.out::println);
//跳过前面的2个数
Stream.of(1,2,3,4,5).skip(2)
.forEach(System.out::print);
// 还有排序,选择等等
Stream.of(32,12,65,79).sorted()
.forEach(e-> System.out.println(e));
}
}
[link]()