Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

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

Government Jobs Opening