Java arraylist of objects


 

Java arraylist of objects

This Java tutorial section, we demonstrates how to use objects in the Java ArrayList.

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

	


          








					






       











		

Ads