Sunday 10 May 2015

How to Remove List From Arraylist

 We can remove  all element of list from arraylist using removeAll().

import java.util.ArrayList;
import java.util.List;

public class RemoveList {

    public static void main(String[] args) {
        ArrayList<String> arr = new ArrayList<String>();
        // add element in arraylist
        arr.add("c");
        arr.add("php");
        arr.add("html");
        arr.add("java");
        // print arraylist
        System.out.println(" berfore remove arrayList is = " + arr);
      
        List<String> brr = new ArrayList<String>();
        brr.add("php");
        brr.add("java");
      
        /*
         * Removes from this list all of its elements that are
           contained in the specified collection.
         */
      
        arr.removeAll(brr);
      
        System.out.println("after remove arraylist is = "+arr);
      
    }
  
}

 Output:

 berfore remove arrayList is = [c, php, html, java]

 after remove arraylist is = [c, html]


Related Posts: 

 


Storing Java Object In ArrayList








No comments:

Post a Comment