Java ArrayList remove Example
ArrayList class remove method example. This example shows you how to use remove method.
ArrayList class remove method example.remove(int index) Removes the element at the specified position in this list. Shifts any subsequent elements to the left.
Here is the code
/**
* @ # Remove.java
* A class repersenting use to remove method of ArrayList class in java.util package
* version 14 May 2008
* author Rose India
*/
import java.util.*;
public class Remove {
public static void main(String args[]) {
List arrlist = new ArrayList();
int i = 0;
String str = "Rose";
//Add the specified element to the end of this list.
arrlist.add(i);
arrlist.add(str);
arrlist.add("India");
System.out.println("arrlist = " + arrlist);
//Remove element of the ArrayList
System.out.println("Removing element is "+arrlist.remove(0));
System.out.println("arrlist = " + arrlist);
}
} |
Output
arrlist = [0, Rose, India]
Removing element is 0
arrlist = [Rose, India] |
|