Java ArrayList.add(E e)

Syntax

ArrayList.add(E e) has the following syntax.

public boolean add(E e)

Example

In the following code shows how to use ArrayList.add(E e) method.


//from w ww.  j a va 2 s.c  om

import java.util.ArrayList;

public class Main {
   public static void main(String[] args) {
      
    ArrayList<Integer>  arrlist = new ArrayList<Integer> (5);

    arrlist.add(15);
    arrlist.add(20);
    arrlist.add(25);
    
    System.out.println(arrlist);
  }
}

The code above generates the following result.