public class Student {
private String name;
private int age;
public Student() {
}
public Student(String name, int age) {
this.name = name;
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
package com.czie.iot1913.lps01;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
/**
* @author 1944900433@qq.com
* @date 2022-03-17 13:21
*/
public class StudentDemo01 {
public static void main(String[] args) {
Collection<Student> c = new ArrayList<Student>();
Student s1 = new Student("刘品金", 41);
Student s2 = new Student("刘品木", 21);
Student s3 = new Student("刘品水", 31);
Student s4 = new Student("刘品火", 51);
Student s5 = new Student("刘品土", 61);
c.add(s1);
c.add(s2);
c.add(s3);
c.add(s4);
c.add(s5);
Iterator<Student> ite = c.iterator();
while (ite.hasNext()) {
Student s = ite.next();
System.out.println(s.getName() + "," + s.getAge());
}
}
}