// Find out why it throws exception at list.remove(d);
import java.util.ArrayList;
import java.util.Iterator;
public class ArrayListExample {
@SuppressWarnings("rawtypes")
public static void main(String[] args) {
ArrayList<Comparable> list=new ArrayList<Comparable>();
//ArrayList<Integer> list=new ArrayList<Integer>();
int a=8;
String b="Anand";
boolean c=true;
list.add(a);
list.add(b);
list.add(c);
int size=list.size();
System.out.println("The size of list is : "+size);
int indexc=list.indexOf(c);
System.out.println("The Index of c is : "+indexc);
char d='A';
list.add(2, d);
System.out.println("The size of list is : "+size);
indexc=list.indexOf(c);
System.out.println("The Index of c is : "+indexc);
System.out.println("The value of d is : "+list.get(list.indexOf(d)));
list.remove(d);
//System.out.println("The Index of c is : "+list.get(list.indexOf(d)));
Iterator<Comparable> itr=list.iterator();
while(itr.hasNext())
{
System.out.println("The elements of list are: "+itr.next());
}
}
}
No comments:
Post a Comment