Monday, March 7, 2016

Choose the right collection for your appication?


Choose the right Java Map interface

HashMap – use this implementation if the order of items while iterating is not important to you. HashMap has better performance compared to TreeMap and LinkedHashMap
TreeMap – is ordered and sorted but slower compared to HashMap. TreeMap has ascending order of keys, according to its Comparator
LinkedHashMap – it orders items by key during insertion

Choose the right Java List interface

ArrayList – items are ordered during insertion. Search operations on ArrayLists is faster compared to search operations on LinkedLists
LinkedList – has fast adding to the start of the list, and fast deletion from the interior via iteration

Choose the right Java Set interface

HashSet – use this implementation if the order of items while iterating is not important to you. HashSet has better performance compared to TreeSet and LinkedHashSet
LinkedHashSet – it orders items during insertion
TreeSet – has ascending order of keys, according to its Comparator

No comments: