Sunday, December 27, 2015

Java Collections

History

          Java 1.0 -> Vector, Dictionary, HashTable, Stack, Enumeration
          Java 1.2 -> Collection, Iterator, List, Set, Map, ArrayList, HashSet, TreeSet, HashMap, WeakHashMap
          Java 1.4 -> Random Access, IdentityHashMap, LinkedHashMap, LinkedHashSet
          Java 1.5 -> Queue, concurrent package
          Java 1.6 -> Deque, ConcurrentSkipListSet & Map ....
          Java 1.7 -> TransferQueue, LInkedTransferQueue

List
  • ArrayList
  • LinkedArrayList
  • CopyOnWriteArrayList ( concurrent )

  • ArrayList
    LInkedList
    CopyOnWriteArrayList
    Data Structure
    Array
    Linked List
    Array
    Iterator
    Fail-fast
    Fail-fast
    Fail-Safe
    Null
    Yes
    Yes
    Yes
    Add
    O(I)
    O(I)
    O(n)
    Remove
    O(n)
    O(I)
    O(n)
    Get
    O(I)
    O(n)
    O(I)
    Contains
    O(n)
    O(n)
    O(n)

      ArrayList
                 - Default capacity 10
                 - Indexed access

Set



















Queue



       PriorityQueue
               - represented as a balanced binary heap.
               - default initial capacity 11

      BlockingQueue

      DelayQueue


TransferQueue
     - Producers may wait for consumers to receive elements. TransferQueue may be useful for example in message passing applications in which producers sometimes await receipt of elements by consumers
     - Similar to SynchronousQueue
             


Deque ( double ended queue )
      - A linear collection that supports element insertion and removal at both ends.

      Implementations
      - LinkedList
      - ArrayDeque
      - LinkedBlockingDeque

Map



      WeakHashMap
          - Hash table based implementation of the Map interface, with weak keys. An entry in a WeakHashMap will automatically be removed when its key is no longer in ordinary use.  
     
IdentityHashMap is a variant on HashMap which tests equality by reference instead of equality by value. Basically, keys and values are compared for equality by checking if their references are equal rather than by calling the "equals" function.

     ConcurrentHashMap 
            - Reference Jenkov JavaHungry

No comments:

Post a Comment