Example of Array List

Here we write as simple Array List program.


package com.javaforecast4u;
import java.util.*;
/**
 *
 * @author arbind
 */
public class TestArrayList {

public static void main(String as[])
{
ArrayList a=new ArrayList();
System.out.println(a.size());
System.out.println(a.isEmpty());

    a.add("arbind");
    a.add("kumar");
    a.add("sharma");
    a.add(new Integer(99));
    a.add(1,"java fore cast") ;

System.out.println(a.size());
System.out.println(a.isEmpty());
System.out.println(a);

System.out.println("......................");
Object o[]=a.toArray();
for(int i=0;i<o.length;i++)
{
System.out.println(o[i]);
}
a.remove("aaa");

//using iterator
   Iterator i=a.iterator();
   while(i.hasNext())
   {
   String str=i.next().toString();
  System.out.println("..."+str);
   }
  }
}



0 comments :

Post a Comment