remove() Method : Java.util.ArrayList
Declaration :
1 |
public E remove(int index) |
Explanation :
Purpose | Method removes the element at the specified position in this list |
Parameters | index ==> The index of the element to be removed |
Return Value | Element that was removed from the list |
Exception | IndexOutOfBoundsException ==> if the index is out of range |
Example
The following example shows the usage of java.util.Arraylist.remove() method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
package com.c4learn.arraylist; import java.util.ArrayList; public class ArrayListExamples { public static void main(String args[]) { // Create ArrayList 1 ArrayList<String> arrlist1 = new ArrayList<String>(5); // Fill Elements in ArrayList 1 arrlist1.add("A"); arrlist1.add("B"); arrlist1.add("C"); arrlist1.add("D"); arrlist1.add("E"); arrlist1.add("F"); // Print Array List String ele = arrlist1.remove(1);; // Print Element's Position System.out.println("Removed Element : " + ele); System.out.println("Array List : " + arrlist1); } } |
Output :
1 2 |
Removed Element : B Array List : [A, C, D, E, F] |