Array Vs Arraylist

Array vs ArrayList in Java

Array is a fixed length information structure though ArrayList is a variable length Collection class. We can’t change length of exhibit once made in Java however ArrayList can be changed.

We can’t store natives in ArrayList, it can just store objects. In any case, cluster can contain the two natives and articles in Java. Since Java 5, natives are consequently changed over in items which is known as auto-boxing.

  1. import java.util.*;
  2. public class ListExample {
  3. public static void main(String[] args) {
  4.     List<Integer> list=new ArrayList<>();
  5.     list.add(Integer.valueOf(10));//storing Integer object
  6.     list.add(20);//Now compiler converts it into Integer.valueOf(20) which is object
  7.     list.add(30);
  8.     System.out.println(“Traversing List…”);
  9.     for(Integer i:list){
  10.         System.out.println(i);
  11.     }
  12. }
  13. }


Traversing List...