Home Tutorial Java Collections Arraylist Java ArrayList removeall

 
 

Share on Google+Share on Google+
Java ArrayList removeall
Posted on: October 23, 2009 at 12:00 AM
Advertisement
This section demonstrates how to use the Java Arraylist RemoveAll

  • removeAll method removes all the elements from the  list which is contained in the second list.
  • list1.removeAll(list2), it will remove all the elements from list1 which is present in the list2


Java Arraylist Removeall Example
import java.util.*;

public class List1 {

public static void main(String[] args) {
String  ar[]={"india","pakistan","United Kingdom","Japan","Korea"};
ArrayList list=new ArrayList();
ArrayList list1=new ArrayList();

list.add(ar[0]);
list.add(ar[1]);
list.add(ar[2]);
list.add(ar[3]);

list1.add("Japan");
list1.add("india");
System.out.println(list+"   ");
list.removeAll(list1);
System.out.println(list+"   ");
}
}

Output
[india, pakistan, United Kingdom, Japan] 
[pakistan, United Kingdom]


Advertisement

Related Tags for Java ArrayList removeall:


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