-
Notifications
You must be signed in to change notification settings - Fork 0
/
Collections7.java
41 lines (36 loc) · 1.02 KB
/
Collections7.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.util.*;
public class Employee
{
int empId;
String empName;
String email;
String gender;
float salary;
Employee(int empId,String empName,String email,String gender,float salary)
{
this.empId=empId;
this.empName=empName;
this.email=email;
this.gender=gender;
this.salary=salary;
}
public static void main(String args[])
{
//Creating user-defined class objects
Employee s1=new Employee(101,"Sonoo","sonoo@gmail.com","Female",35000);
Employee s2=new Employee(102,"Anu","anu@gmail.com","Female",35020);
//creating arraylist
Vector<Employee> al=new Vector<Employee>();
al.add(s1);//adding Student class object
al.add(s2);
//al.add(s3);
//Getting Iterator
Iterator itr=al.iterator();
//traversing elements of ArrayList object
while(itr.hasNext())
{
Employee st=(Employee)itr.next();
System.out.println(st.empId+" "+st.empName+" "+st.email+" "+st.gender+" "+st.salary);
}
}
}