Tuesday, June 19, 2007

Litttle Sugar (Java Collections)

The other day I was reading about java collections . I came accross this trivial point about Sets in java that is worth remembering . In java there are 3 different implementations of the Set interface , namely :
  1. HashSet
  2. TreeSet
  3. LinkedHashSet
HashSet:
The fastest among the 3 implementations , but does not maintain ordering.

TreeSet:
The slowest among the 3 implementations , uses red black tree to internally store items and orders the items by value.

LinkedHashSet:
Its performance comes in between the 1st two but maintain the ordering in which items are
inserted . Uses hashtable with linked list to store items.