java流式编程的流的生成方式
流:
- 集合流
- Map流
- 数组流
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Stream;
//几种流的生成方式
public class StreamDemo2 {
public static void main(String[] args) {
//Collections生成流
ArrayList<String> strings = new ArrayList<>();
Stream<String> stream = strings.stream();
//map的流
Map<Integer, Integer> integerIntegerMap = new HashMap<>();
//键的流
Stream<Integer> stream1 = integerIntegerMap.keySet().stream();
//值得流
Stream<Integer> stream2 = integerIntegerMap.values().stream();
//键值对得流
Stream<Map.Entry<Integer, Integer>> stream3 = integerIntegerMap.entrySet().stream();
//数组得流
int[] a = {1,2,3,4,5,6,7};
Stream<int[]> a1 = Stream.of(a);
}
}