- TreeMap
- Red-black tree based
- Ordered for key
- LinkedHashMap
- Hashtable and linked list based
- Insertion order preserved
- EnumMap
- Key must come from an enum
- Might be (but not guaranteed) faster than other map
- HashMap
- Hashtable based map
- Allow multiple null value and one null key
- Unsynchronized
- No order of key or value
- ConcurrentHashMap
- More modern than hashtable
- Use more buckets therefore less likely to be blocked
- May miss updates when iterating through existing elements, using provided iterator
- Lock only portion not the whole map whenever possible
- http://stackoverflow.com/questions/510632/whats-the-difference-between-concurrenthashmap-and-collections-synchronizedmap
- http://stackoverflow.com/questions/510632/whats-the-difference-between-concurrenthashmap-and-collections-synchronizedmap
- Collections.synchronizedMap blocks the whole map for all operations, therefore performance degrades a lot under heavy load
- Hashtable
- Synchronized
- No null value or key allowed
- Blocking queue
- Sometimes you might be asked to implement it (56. linkedin interview (java lib implementation))
- Sometimes you might be asked to implement it (56. linkedin interview (java lib implementation))
- LinkedList vs ArrayList
- Both implement List interface
- LinkedList is link list based also implements Deque interface, while ArrayList is array based and implements RandomAccess interface
- ArrayList preferred over Vector
- ArrayList is not synchronized while Vector is.
- Vector is considered "obsoleted" and should always use ArrayList if possible
- http://stackoverflow.com/questions/11375392/vector-vs-arraylist-which-is-better
- http://stackoverflow.com/questions/1386275/why-is-java-vector-class-considered-obsolete-or-deprecated
- ArrayDeqeue preferred over Stack
- ArrayDeqeue can support either FIFO or LIFO
- ArrayDeque is resizable-array based therefore might be faster than normal Stack and LinkedList, which also implements Deque interface
- The key here is that you need to choose the one that best suits your application nature. If you know most of time your application has limited stuff to hold and/or no need to remove element in the middle then array based ArrayDeqeue might be better. If you really desire real-time control and do not want to waste time in array resizing and/or need to remove lots of elements in the middle then LinkedList might be better.
- http://stackoverflow.com/questions/6163166/why-is-arraydeque-better-than-linkedlist
- http://stackoverflow.com/questions/12524826/why-should-i-use-deque-over-stack
- Segment tree and interval tree
- RESERVED
Frequently used Java class and ADT
最新推荐文章于 2020-02-02 15:22:20 发布