Thursday, April 9, 2015

Java Collection


Some key information on Collection:

  • List can contain duplicate elements whereas Set contains only unique elements.
  • Set contains values only whereas Map contains key and values both.
  • HashSet maintains no order whereas TreeSet maintains ascending order.
  • HashSet contains only values whereas HashMap contains entry(key,value). HashSet can be iterated but HashMap need to convert into Set to be iterated.
  • HashMap maintains no order but TreeMap maintains ascending order.
  • Collection is an interface whereas Collections is a class. Collection interface provides normal functionality of data structure to List, Set and Queue. But, Collections class is to sort and synchronize collection elements.

No comments: