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]
Storing Java Object In ArrayList
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
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:
How to count number of element in ArrayList
How to insert element in arraylist
How to use retailAll in arraylist
No comments:
Post a Comment