java获取stream流
可以通过以下四种方式获取
1 通过list集合获取,list.stream()
List<String> list = new ArrayList<>();
list.add("北京");
list.add("上海");
list.add("广州");
Stream<String> stream = list.stream();
stream.forEach(s -> System.out.println(s));
System.out.println("============================");
2 通过Set集合获取,map.keySet().stream()
Map<String, String> map = new HashMap<>();
map.put("id", "1");
map.put("name", "邓超");
Set<String> keySet = map.keySet();
Stream<String> keyStream = map.keySet().stream();
Stream<String> valueStream = map.values().stream();
keyStream.forEach(s -> System.out.println(s));
System.out.println("============================");
valueStream.forEach(s -> System.out.println(s));
System.out.println("============================");
3 通过数组获取,Arrays.stream
String[] str = {"郑州", "武汉", "长沙"};
Stream<String> stream1 = Arrays.stream(str);
stream1.forEach(s -> System.out.println(s));
System.out.println("============================");
4 同种类型的多个数据,直接通过Stream接口的静态方法of(T... values)生成流
Stream<String> stream2 = Stream.of("郑州", "武汉", "长沙");
stream2.forEach(s -> System.out.println(s));
标签:map,java,Stream,stream,System,获取,println,out
From: https://www.cnblogs.com/jinxin1/p/17006101.html