class Student{
int rollno;
String name;
int age;
Student(int rollno, String name, int age ){
this.rollno = rollno;
this.name = rollno;
}
}
import java.util.*;
public class ArrayListUsingClasses{
public static void main(String args[]){
//crearting user defined class object;
Student s1 = new Student(100,"Monu",32);
Student s2 = new Student(101,"Sonu",30);
Student s3 = new Student(102,"Mukka",28);
//defining an arraylist;
ArrayList<Student> arr = new ArrayList<Student>();
//adding student class object
arr.add(s1);
arr.add(s2);
arr.add(s3);
//getting iterator
Iterator itr = arr.iterator();
//traversing elements of Arraylist object;
while(itr.hasNext()){
Student st = (Student)itr.next();
System.out.println(st.rollno+" "+st.age+""+st.name);
}
}
}