ArrayList extends AbstractList and implements List interface.
Example:
import java.util.*;
class demo
{
public static void main(String[] args){
ArrayList
al.add("bhabani");
al.add("pinku");
al.add("mahesh");
al.add("arvind");
al.add("arjan");
System.out.println("size of array list is:"+al.size());
System.out.println(al);//to display the list
al.remove(2);//to remove an element
//al.remove("mahesh");//same as above line
System.out.println(al);
System.out.println(al.contains("bhabani"));//whether one element exist
al.removeAll(al);//to remove all elements
System.out.println(al);
System.out.println(al.isEmpty());//whether the list is empty
}};
No comments:
Post a Comment