Organizational Research By

Surprising Reserch Topic

Java ArrayList add() Method Example

Here we are discussing about add() method of Java.util.ArrayList class. This method is used for adding an element to the ArrayList. Below is the method signature:

public boolean add(Object element)


import java.util.ArrayList;
public class Details {
    public static void main(String[] args) {

        //ArrayList Declaration
        ArrayList al= new ArrayList();
        //add method for String ArrayList
        System.out.println("Elements of ArrayList of String Type: "+al);

        //ArrayList Declaration
        ArrayList al2 = new ArrayList();
        //add method for integer ArrayList
        System.out.println("Elements of ArrayList of Integer Type: "+al2);

Elements of ArrayList of String Type: [Ram, Shyam, CPS, John, Steve]
Elements of ArrayList of Integer Type: [1, 34, 99, 99, 78]

asked Jun 11, 2015 in Java Interview Questions by rajesh
0 votes

Related Hot Questions

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.