- 一、forEach方法
一、forEach方法
java.util.function.Consumer接口是一个消费型接口。
Consumer接口中包含抽象方法void accept(T t),意为消费一个指定泛型的数据。
void forEach(Consumer<? super T> action);
@Test
void test8() {
List<People> peopleList = new ArrayList<>();
peopleList.add(new People(1, "小王", 1));
peopleList.add(new People(2, "小李", 2));
peopleList.add(new People(3, "小张", 2));
peopleList.add(new People(4, "小皇", 1));
peopleList.stream().forEach(s -> {
s.setJgid(s.getJgid()+1);
System.out.println(s);
});
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)