import java.util.ArrayList;
import java.util.Collections;
public class Demo01List {
public static void main(String[] args) {
List list = new ArrayList<>();
Collections.addAll(list, "张无忌", "周芷若", "赵敏", "张强", "张三丰");
List listA = new ArrayList<>();
List listB = new ArrayList<>();
System.out.print(s+"\t");
- 使用Stream流的方式,遍历集合,对集合中的数据进行过滤
- Stream流是JDK1.8之后出现的,关注的是做什么,而不是怎么做
import java.util.ArrayList;
import java.util.Collections;
public class Demo02Stream {
public static void main(String[] args) {
List list = new ArrayList<>();
Collections.addAll(list, "张无忌", "周芷若", "赵敏", "张强", "张三丰");
list.stream().filter(name -> name.startsWith("张"))
.filter(name -> name.length() == 3)
.forEach(System.out::println);