//---------------Collection集合获取流---------
Collection<String> list = new ArrayList<>();
Stream<String> s = list.stream();
//----------------Map集合获取流------------
HashMap<String, Integer> maps = new HashMap<>();
//键流
Set<String> set = maps.keySet();
Stream<String> st2 = set.stream();
//值流
Collection<Integer> vs = maps.values();
Stream<Integer> st1 = vs.stream();
//键值对流
Set<Map.Entry<String, Integer>> entries = maps.entrySet();
Stream<Map.Entry<String, Integer>> st3 = entries.stream();
//------------------------数组获取流--------------------
String[] names = {"洋洋","小王","小航","小雪"};
Stream<String> nameStream = Arrays.stream(names);
Stream<String> namesStream2 = Stream.of(names);
ArrayList<String> names = new ArrayList<>();
Collections.addAll(names,"张三丰","张无忌","周芷若","赵敏","张强");
//1. 从集合中找出姓张的放到新集合
ArrayList<String> zhangList = new ArrayList<>();
for (String name :names) {
if (name.startsWith("张")){
zhangList.add(name);
}
}
//2.找名称长度是3的姓名
ArrayList<String> threeName = new ArrayList<>();
for (String name :names) {
if (name.length()==3){
threeName.add(name);
}
}
System.out.println(threeName);
//3.使用Stream实现