首先是这个代码中的Students,这个对象是创建了一个名叫s的对象名然后以此来调用Students类中的方法
public static void add(ArrayList<Students> array) {
Scanner sc = new Scanner(System.in);
System.out.println("please enter the code");
String code = sc.nextLine();
System.out.println("please enter the name");
String name = sc.nextLine();
System.out.println("please enter the age");
String age = sc.nextLine();
System.out.println("please enter the address");
String address = sc.nextLine();
Students s = new Students();
s.setCode(code);
s.setName(name);
s.setAge(age);
s.setAddress(address);
array.add(s);
System.out.println("added successfully");
}
然后因为arrayLIst是最近学的可能没有融会贯通所以,在以下代码中s后的array.get();又起什么作用或者含义呢?
public static void checkAll(ArrayList<Students> array) {
System.out.println("学号 名字 年龄 地址");
for (int a = 0; a < array.size(); a++) {
Students s = array.get(a);
System.out.println(s.getCode() + " " + s.getName() + " " + s.getAge() + " old " + s.getAddress());
}
}