三种较新的遍历list数组的方式

数据: List< Student > studentList;

  1. 通过增强for循环
		for (Student student : studentList) {
    
    
	    	System.out.println(student);
		}
  1. 通过流stream方式遍历
        //@FunctionalInterface 函数式接口
        studentList.stream().forEach(new Consumer<Student>(){
    
    
            //接收对象 对Student对象的处理
            @Override
            public void accept(Student student) {
    
    
                System.out.println(student);
            }
        });

  1. 通过函数式接口方式遍历 (函数式接口只有一个方法被调用)
		//  (函数式接口方法声明)->{方法代码}
        System.out.println("\n   ===函数式接口方法遍历输出  ===   ");
        studentList.stream().forEach(student->{
    
    
            System.out.println(student);
        });

猜你喜欢

转载自blog.csdn.net/qq_40542534/article/details/108804633