1、认识
2、Stream流使用步骤
3、如何获取Stream流
List<String> list=new ArrayList<>();
Collections.addAll(list,"崔十一","张天年","张家","张天爱");
List<String> l = list.stream().filter(s -> s.startsWith("张") && s.length() == 3).collect(Collectors.toList());
System.out.println(l);
Set<String> set=new HashSet<>();
Collections.addAll(list,"崔十一","张天年","张家","张天爱");
Set<String> l1 = list.stream().filter(s -> s.startsWith("张") && s.length() == 3).collect(Collectors.toSet());
System.out.println(l1);
Map<String,Integer> map=new HashMap<>();
map.put("java",100);
map.put("java1",200);
map.put("java2",300);
map.keySet().stream().filter(s->s.contains("1")).forEach(s -> System.out.println(s));
map.values().stream().filter(s->s>=200).forEach(System.out::println);
Set<Map.Entry<String, Integer>> entries = map.entrySet();
entries.stream().forEach(kvs-> System.out.println(kvs.getKey()+"-->"+kvs.getValue()));
int[] a=new int[]{1,2,3};
Arrays.stream(a).filter(s->s>=2).forEach(System.out::println);
Stream.of(a).forEach(System.out::println);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
4.Stream流的中间方法
5、 Stream流终结方法