Frequently used Java class and ADT

  1. TreeMap
    1. Red-black tree based
    2. Ordered for key
  2. LinkedHashMap
    1. Hashtable and linked list based
    2. Insertion order preserved
  3. EnumMap
    1. Key must come from an enum
    2. Might be (but not guaranteed) faster than other map
  4. HashMap
    1. Hashtable based map
    2. Allow multiple null value and one null key
    3. Unsynchronized 
    4. No order of key or value
  5. ConcurrentHashMap
    1. More modern than hashtable
    2. Use more buckets therefore less likely to be blocked
    3. May miss updates when iterating through existing elements, using provided iterator
    4. Lock only portion not the whole map whenever possible
      1. http://stackoverflow.com/questions/510632/whats-the-difference-between-concurrenthashmap-and-collections-synchronizedmap
    5. Collections.synchronizedMap blocks the whole map for all operations, therefore performance degrades a lot under heavy load
  6. Hashtable
    1. Synchronized
    2. No null value or key allowed
  7. Blocking queue
    1. Sometimes you might be asked to implement it (56. linkedin interview (java lib implementation))
  8. LinkedList vs ArrayList
    1. Both implement List interface
    2. LinkedList is link list based also implements Deque interface, while ArrayList is array based and implements RandomAccess interface
  9. ArrayList preferred over Vector
    1. ArrayList is not synchronized while Vector is.
    2. Vector is considered "obsoleted" and should always use ArrayList if possible
    3. http://stackoverflow.com/questions/11375392/vector-vs-arraylist-which-is-better
    4. http://stackoverflow.com/questions/1386275/why-is-java-vector-class-considered-obsolete-or-deprecated
  10. ArrayDeqeue preferred over Stack
    1. ArrayDeqeue can support either FIFO or LIFO
    2. ArrayDeque is resizable-array based therefore might be faster than normal Stack and LinkedList, which also implements Deque interface
    3. 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.
    4. http://stackoverflow.com/questions/6163166/why-is-arraydeque-better-than-linkedlist
    5. http://stackoverflow.com/questions/12524826/why-should-i-use-deque-over-stack
  11. Segment tree and interval tree
  12. RESERVED
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值