package com.sise05; import java.util.ArrayList; public class Test { public static void main(String[] args) { Student stu1=new Student("lali",10); Student stu2=new Student("jennie",20); Student stu3=new Student("jisoo",30); ArrayList<Student> arrayList=new ArrayList<>(); arrayList.add(stu1); arrayList.add(stu2); arrayList.add(stu3); for (int i=0;i<arrayList.size();i++){ Student s=arrayList.get(i); System.out.println("Name:"+s.getName()+" "+"Age:"+s.getAge()); } } }
package com.sise05; public class Student { private String name; private int age; public Student(String name, int age) { 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; } }