package test.game;
import java.util.ArrayList;
import java.util.List;
class Student {
private String name;
private int age;
public Student(){
}
public Student(String name, int age) {
super();
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;
}
@Override
public String toString() {
return "Student [name=" + name + ", age=" + age + "]";
}
}
public class Print {
public static void main(String[] args) {
List<Student> arr = new ArrayList<Student>();
arr.add(new Student("张三",22));
arr.add(new Student("李四",16));
arr.add(new Student("王五",33));
arr.add(new Student("赵琦",23));
arr.add(new Student("刘佳",13));
for(Student s:arr){
System.out.println(s);
}
}
}
结果:
Student [name=张三, age=22]
Student [name=李四, age=16]
Student [name=王五, age=33]
Student [name=赵琦, age=23]
Student [name=刘佳, age=13]
最好用容器,之后遍历,可以很容器存取数据。 |