stream是java8中用来表示元素的一种序列,提供了很多方便的操作提高开发效率。
List.of("hello", "world").stream().limit(1).forEach(System.out::println);
String[] arry = {"java", " ","python", "go", "hello"};
Arrays.stream(arry).forEach(System.out::println);
String[] arry = {"java", " ","python", "go", "hello"};
Stream.of(arry).forEach(System.out::println);
Stream.generate(() -> new Random(10)).limit(10).forEach(System.out::println);
Stream.iterate(1, i -> i+1).limit(10).forEach(System.out::println);
public class StreamOpTest {
public static void main(String[] args) {
String[] strArry = {"java","python","","go", "c++_demo","python"};
Arrays.stream(strArry)
.filter(x -> !x.isEmpty())
.distinct()
.sorted()
.limit(1)
.map(i -> i.replace("_", ""))
.flatMap(str -> Stream.of(str.split("")))
.forEach(System.out::println);
}
}
原文:https://www.cnblogs.com/decoo/p/14249121.html