Home Tutorial Java Collections Arraylist Java arraylist remove

 
 

Share on Google+Share on Google+
Java arraylist remove
Posted on: October 23, 2009 at 12:00 AM
Advertisement
This java tutorial chapter we demonstrates how to use the method remove() in the Java ArrayList.

  • remove() method is used to remove the element of the arrayList.
  • It has two forms
    1. remove(Object)
    2. remove(index)


Java Arraylist Remove Example
import java.util.*;

public class List1 {
public static void main(String[] args) {
Integer ar[]={111,222,333,444};
List list=new ArrayList();
list.add(ar[0]);
list.add(ar[1]);
list.add(ar[2]);
list.add(ar[3]);
System.out.println("With all element "+list);
list.remove(ar[0]);
System.out.println("after removal of first index"+list);
list.remove(2);
System.out.println("after removal of index 2"+list);
  }
}
Output
With all element [111, 222, 333, 444]
after removal of first index[222, 333, 444]
after removal of index 2[222, 333]
Advertisement

Related Tags for Java arraylist remove:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: October 23, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com