Sunday, February 22, 2009

Example code for simple ArrayList



// simple arraylist Application
package collection;

import java.util.*;

class SampleArrayList
{
public static void main(String[] args)
{

ArrayList a1=new ArrayList();

a1.add(new Integer(10));
a1.add("hello");
a1.add(new Integer(20));
a1.add(new Integer(30));

System.out.println(a1); // here ArryList toString method called

// By using iterator

Iterator i1=a1.iterator();

while(i1.hasNext())
System.out.println(i1.next());


}
}


output:
[10, hello, 20, 30]
10
hello
20
30



0 comments:

Post a Comment