forked from anandpatel88/JavaPrograms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayListPgmGeneric.java
More file actions
36 lines (31 loc) · 845 Bytes
/
Copy pathArrayListPgmGeneric.java
File metadata and controls
36 lines (31 loc) · 845 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 JavaPgm;
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListPgmGeneric {
public static void main(String[] args) {
ArrayList<String> aLs=new ArrayList<String>();
aLs.add("Anand");
aLs.add("Mohan");
aLs.add("Patel");
System.out.println("Lis is"+aLs);
String title=aLs.get(2);
System.out.println("title is " +title);
System.out.println(aLs.size());
System.out.println("########Simple For########");
for(int i=0;i<aLs.size();i++)
{
System.out.println(aLs.get(i));
}
System.out.println("########Each For########");
for(String s:aLs)
{
System.out.println(s);
}
System.out.println("###########Using Iterator########");
Iterator<String> it=aLs.iterator();
while(it.hasNext())
{
System.out.println(it.next());
}
}
}