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 LinkedHashMapTreeMap – 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 LinkedListsLinkedList – 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 LinkedHashSetLinkedHashSet – it orders items during insertion
TreeSet – has ascending order of keys, according to its Comparator
No comments:
Post a Comment