一 forEach 源码:void forEach ( Consumer ? super T action ); /** * @Author yqq * @Date 2021/4/15 22:38 * @Version 1.0 */ public class ForEachDemo { public static void main ( String [] args ) { List People list = new ArrayList (); list .
一 forEach
* @Author yqq
* @Date 2021/4/15 22:38
* @Version 1.0
*/
public class ForEachDemo {
public static void main(String[] args) {
List<People> list=new ArrayList<>();
list.add(new People("1","科比",24));
list.add(new People("2","詹姆斯",6));
list.add(new People("3","杜兰特",35));
list.add(new People("4","威斯布鲁克",0));
list.add(new People("5","乔丹",23));
list.stream()
.forEach(e -> {
System.out.println(e.getName());
});
}
}
输出:
科比
詹姆斯
杜兰特
威斯布鲁克
乔丹