外国风格网站建设价格,seowhy培训,wordpress如何使用插件,建设银行网站邮箱筛选#xff0c;是按照一定的规则校验流中的元素#xff0c;将符合条件的元素提取到新的流中的操作。 「案例一#xff1a;筛选出Integer集合中大于7的元素#xff0c;并打印出来」
public class StreamTest {public static void main(String[] args) {ListInteger是按照一定的规则校验流中的元素将符合条件的元素提取到新的流中的操作。 「案例一筛选出Integer集合中大于7的元素并打印出来」
public class StreamTest {public static void main(String[] args) {ListInteger list Arrays.asList(6, 7, 3, 8, 1, 2, 9);StreamInteger stream list.stream();stream.filter(x - x 7).forEach(System.out::println);}
}
「案例二筛选员工中工资高于8000的人并形成新的集合。」 形成新集合依赖collect收集后文有详细介绍。
public class StreamTest {public static void main(String[] args) {ListPerson personList new ArrayListPerson();personList.add(new Person(Tom, 8900, 23, male, New York));personList.add(new Person(Jack, 7000, 25, male, Washington));personList.add(new Person(Lily, 7800, 21, female, Washington));personList.add(new Person(Anni, 8200, 24, female, New York));personList.add(new Person(Owen, 9500, 25, male, New York));personList.add(new Person(Alisa, 7900, 26, female, New York));ListString fiterList personList.stream().filter(x - x.getSalary() 8000).map(Person::getName).collect(Collectors.toList());System.out.print(高于8000的员工姓名 fiterList);}
}