Home Tutorial Java Collections Arraylist Java arraylist of objects

 
 

Java arraylist of objects
Posted on: October 23, 2009 at 12:00 AM
Advertisement
This Java tutorial section, we demonstrates how to use objects in the Java ArrayList.

  • In arrayList object is added by default
  • This can be object of String, Integer or any Wrapper class


Example of Java Arraylist of Objects
import java.util.ArrayList;
import java.util.List;

public class List1 {
    public static void main(String[] args) {
       String name1=new String("mac");
       String name2=new String("jack");
       String name3=new String("john");
       String name4=new String("rob");

       List list=new ArrayList(4);
       list.add(0,name2);
       list.add(1,name1);
       list.add(2,name3);
       list.add(3,name4);
      
         for(int x=0;x







					
					
Advertisement

Related Tags for Java arraylist of objects:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com