Java ArrayList remove Example
ArrayList class remove method example. This example shows you how to use remove method.
ArrayList class remove method example.public boolean remove(Object o) Removes the first occurrence of the specified element from this list, if it is present. If the list does not contain the element, it is unchanged.
Here is the code
/**
* @ # Remove1.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 Remove1 {
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("Element is in the list : "+arrlist.remove("India"));
System.out.println("arrlist = " + arrlist);
}
} |
Output
arrlist = [0, Rose, India]
Element is in the list : true
arrlist = [0, Rose] |
|