add() Method : Java.util.ArrayList
Declaration :
1 |
public boolean add(E ele) |
Explanation :
Purpose | Method appends the specified element E to the end of the list. |
Parameters | ele ==> The element to be appended to this list. |
Return Value | Method returns true. |
Exception | NA |
Example
The following example shows the usage of java.util.Arraylist.add(E) method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
package com.c4learn.arraylist; import java.util.ArrayList; public class ArrayListExamples { public static void main(String[] args) { // Create ArrayList ArrayList<String> arrList1 = new ArrayList<String>(); arrList1.add("Vehicle 1"); arrList1.add("Vehicle 2"); arrList1.add("Vehicle 3"); arrList1.add("Vehicle 4"); // Display Array List System.out.println(arrList1); } } |
Output :
1 |
[Vehicle 1, Vehicle 2, Vehicle 3, Vehicle 4] |