将对象添加到现有ArrayList

时间:2013-04-18 21:12:56

标签: java android arraylist

我有一个带有对象的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".
}

请帮忙。感谢。

1 个答案:

答案 0 :(得分:0)

尝试使用ArrayList.addAll(...)