public static class Student{
        private String name;
        private String sex;
        private String age;

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

public static void main(String[] args) {
        Student student = new Student();
        student.setName("张三");
        student.setSex("女");
        student.setAge("18");
        Student student1 = new Student();
        student1.setName("王美美");
        student1.setSex("男");
        student1.setAge("57");
        List<Student> studentList = new ArrayList<>();
        studentList.add(student);
        studentList.add(student1);
        studentList.stream().forEach(stu->{
            System.out.println(stu.getName());
        });
    }
打印结果:
张三
王美美

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-04
  • 2022-02-14
  • 2022-12-23
  • 2021-10-08
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-15
  • 2022-12-23
  • 2021-07-12
  • 2022-12-23
  • 2022-12-23
  • 2021-12-21
相关资源
相似解决方案