LOADING

加载过慢请开启缓存 浏览器默认开启

Stream流

2023/4/10 Java Java

Stream流式思想的核心

1.先得到集合或者数组的Stream流

2.把元素放上去

3.然后就用这个Stream流简化的API来方便的操作元素。

示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package Stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
* @author Administrator
* @version 1.0
* @description TODO
* @date 2023/4/10 14:08
*/
public class test {
public static void main(String[] args) {
List<String> names=new ArrayList<>();
Collections.addAll(names,"张三丰","张无忌","殷素素","宋远桥","张强");
System.out.println(names);
names.stream().filter(s->s.startsWith("张")&&s.length()==3).forEach(s-> System.out.println(s));
}
}