0% found this document useful (0 votes)
21 views1 page

Java - Util.Arraylist - Add Method: Description

The java.util.ArrayList.add() method appends an element to the end of the ArrayList. It returns true and takes the element to add as a parameter. The example demonstrates creating an ArrayList of Integers, using the add() method to insert elements, and printing out the elements.

Uploaded by

Minh Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Java - Util.Arraylist - Add Method: Description

The java.util.ArrayList.add() method appends an element to the end of the ArrayList. It returns true and takes the element to add as a parameter. The example demonstrates creating an ArrayList of Integers, using the add() method to insert elements, and printing out the elements.

Uploaded by

Minh Nguyen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

JAVA.UTIL.ARRAYLIST.

ADD() METHOD
http://www.tuto rialspo int.co m/java/util/arraylist_add.htm
Co pyrig ht tuto rials po int.co m

Description
T he java.util.ArrayList.add(E e) method appends the specified element E to the end of the list.

Declaration
Following is the declaration for java.util.ArrayList.add() method
public boolean add(E e)

Parameters
e -- T he element to be appended to this list.

Return Value
T his method returns true.

Exception
NA

Example
T he following example shows the usag e of java.util.Arraylist.add(E) method.
package com.tutorialspoint; import java.util.ArrayList; public class ArrayListDemo { public static void main(String[] args) { // create an empty array list with an initial capacity ArrayList<Integer> arrlist = new ArrayList<Integer>(5); // use add() method to add elements in the list arrlist.add(15); arrlist.add(20); arrlist.add(25); // let us print all the elements available in list for (Integer number : arrlist) { System.out.println("Number = " + number); } } }

Let us compile and run the above prog ram, this will produce the following result:
Number = 15 Number = 20 Number = 25

You might also like