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

 

Leave a Reply

Your email address will not be published. Required fields are marked *

7 + 2 =