Difference between ArrayList and Collection

Collection:

Collection col = new ArrayList();

Iterator col_iter = col.iterator();

  1. You will not able to get the arraylist value by its index. (col_iter.get(index) method does not exist).
  2. Set firstSet = new HashSet();

You can able to assign the col_iter = firstSet; without any casting.

ArrayList:

ArrayList al = new ArrayList();

Iterator al_iter = al.iterator();

  1. You can access the arraylist value by its index. (al_iter.get(index) method helps to get the value by its index).
  2. Set secondSet = new HashSet();

You must do casting to assign set to arraylist

col_iter = (ArrayList)secondSet;

 

 

 

Thanks for reading this post……………!!!

Leave a Reply