0

あるクラスにオブジェクトを持つ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".
}

助けてください。ありがとう。

4

1 に答える 1