-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathArrayListDemo.java
More file actions
36 lines (30 loc) · 816 Bytes
/
ArrayListDemo.java
File metadata and controls
36 lines (30 loc) · 816 Bytes
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
package com.collection;
import java.util.ArrayList;
public class ArrayListDemo {
public static void main(String[] args) {
ArrayList list = new ArrayList();
list.add(new Integer(10));
list.add(new Float(20.6));
list.add(new String("ABC"));
list.add("Welcome");
list.add(30.8);
list.add(1, "HI");
list.add(30.8);
list.add(new Employee(10,"Sakshi",10.5f));
list.add(new Employee(12,"Palak",13.5f));
for(int i=0;i<list.size();i++)
{
Object obj = list.get(i);
if(obj instanceof Employee){
System.out.println("Employee Details:");
System.out.println("Id: "+((Employee)obj).getId());
System.out.println("Name: "+((Employee)obj).getName());
System.out.println("Salary: "+((Employee)obj).getSalary());
}
else
{
System.out.println(obj);
}
}
}
}