Sunday 10 May 2015

how To Remove Element of arraylist

There we will remove one element of arraylist using remove().


import java.util.ArrayList;

public class RemoveElement {
              
    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("Before Remove Element ArrayList is = " + arr);
      
        /*
         * Removes the element at the specified position in this
           list. Shifts any subsequent elements to the left
         */
      
        arr.remove(1);
      
        System.out.println("After Remove Element ArrayList is="+arr);
      
    }
}

 Output:

Before Remove Element ArrayList is = [c, php, html, java]

After Remove Element ArrayList is=[c, html, java]




Related Posts: 

 


Storing Java Object In ArrayList




No comments:

Post a Comment