我有一个包含一个类中的对象的arrayList,而在另一个类中,我正在获取包含所有对象的arrayList,并希望在最后向该ArrayList 添加另一个新对象。
我的代码目前是这样的:
ArrayList<Student> studentName = new ArrayList<Student>();
Student student = new Student();
student.name("Jhon");
studentName.add(student);
//In another class I am getting the arrayList with existing objects
for (Student stu : ArrayList<Student> student){
System.out.printLn(stu.name);//prints existing student Name
// Here I want to add a new student name in the name arraylist at the end.
// output should be suppose.."Jhon", "Becky".
}
请帮忙。谢谢。