A List of Java Container Classes

A List of Java Container Classes

I spend a lot of my time programming in Java. I refer to it as my favorite programming language, as it was my first *real* programming language, I therefor naturally have bias toward it. The other day I was thinking, “Wouldn’t it be nice to have a centrally located list of all the Java container type classes for easy reference?”. Well, here it is.. I don’t imagine that it is an exhaustive list, so read up, and if i missed 1 or 2 or 5, post up a comment to let me know what I forgot.

  • AbstractList: A member of the Java collections framework. This implementation is only a bare bones implementation. This class supports Random Access. AbstractSequentialList, ArrayList, and Vector classes are derived from this class.
  • AbstractMap Classes: AbstractMap is a super class for ConcurrentHashMap, EnumMap, HashMap, IdentityHashMap, TreeMap, and WeakHashMap a family of containers which generally use hash functions to determine object placement in the table structure. Subclasses which use this class are known for very fast random access.

  • AbstractSet: AbstractSet is a superclass to CopyOnWriteArraySet, EnumSet, HashSet,and TreeSet.

  • AbstractSequentialList: This class is a member of the Java collections framework. This implementation is only a bare bones implementation. This class is built for sequential access. Linked Lists are Derived from this class.

  • ArrayList: Ammortized constant time add. Get, set, size, isEmpty, interator and listIterator run in constant time. This structure is dynamically expanding. similar to the idea of a vector in c++. This class is not threadsafe by default. This class will add an additional amount of storage equal to 50% of the previous ArrayList size when it needs more storage.

  • BitSet: A BitSet is a container for bits that grows dynamically. BitSets are great containers for 1’s and 0’s 8) . you can perform logical operations on BitSets as well. BitSets are not threadsafe.

  • Buffer classes: The classes ByteBuffer, CharBuffer, DoubleBuffer, FloatBuffer, IntBuffer, LongBuffer, and ShortBuffer are all primitive type containers based from an abstract superclass called Buffer. The subclasses of Buffer can all be created as read only buffers. These classes are also not type-safe. The buffers included in the buffer class may reside outside the scope of garbage collection.

  • ConcurrentHashMap: A Hashtable that supports nearly full concurrency. All operations are threadsafe in this class, but the caveat is that data reads are non-locking, and there is no support for locking the whole table during reads. Data access therefore reflects the most recent completed write.

  • CopyOnWriteArraySet: A thread safe version of ArrayList, in which a copy of the underlying array is operated on. This is obviously an expensive option to consider, but for arrays in which reads are significantly more common than writes, it is a viable option. When the iterator is created, a snapshot of the array is created for traversal.

  • EnumMap: This is a special class built for enum type keys. EnumMaps can contain only one type of enum, which can be declared implicitly or explicitly. EnumMaps are not synchronized.

  • EnumSet: Enumset is a container for Enum objects. EnumSets can contain only one type of enum, which can be declared implicitly or explicitly. EnumSets are not synchronized and are not thread safe.

  • HashMap: A Hashmap is Java’s version of a hash table. This implementation uses the Map interface for object containment. As with all hash storage methods, the trade-off for constant time access is the need for periodic rehashing if storage becomes an issue.

  • HashSet: This class brings constant time performance to the set interface. Iteration performance is in O(n) time. The implementation is not thread safe.

  • IdentityHashMap: This class is not used often at all, and is not recommended for use, except in very specific circumstances. If reference equality semantics are important, then this is the storage class for you. This class implementation is not thread safe.

  • List: List is effectively a object oriented implementation of the primitive array.

  • LinkedList: Java’s version of a singly linked list.

  • LinkedHashMap: This class provides a structure which is a hashmap and linked list. LinkedHashMaps maintain a doubly linked list through all entries.

  • LinkedHashSet: This class is an implementation of a hash table and linked list using the set interface. It is different from HashSet in that it maintains a doubly linked list through all of its entries. Basic operations are in constant time.

  • MapList: Maplists are Hashtables based on the Map interface. This class provides constant time performance for get and put operations, but operations including rehash of data provide a counter balance to this storage method. HashMaps are not thread safe in the default implementation.

  • Primitive array: This is the statically sized, c programmer version of the array. High performance, and low overhead make this a popular choice for simple programs, as well as programs which need a low memory footprint.

  • Queue classes: The classes which inherit from queue include AbstractQueue, ArrayBlockingQueue, ConcurrentLinkedQueue, DelayQueue, LinkedBlockingQueue, LinkedList, PriorityBlockingQueue, PriorityQueue, and

  • Stack: This is the classic Last In, First Out(LIFO) stack. It is built on top of the vector class, so it is dynamic in size.

  • SynchronousQueue: These classes share the characteristics that ordering is generally First In, First Out (FIFO) ordering, with the exception of the classes considered priority queue classes.

  • TreeMap: This is an implementation of a Red-Black tree on the sorted map interface. ContainsKey, gets, puts and removes are all guaranteed O(log(n)). The implementation is not thread safe by default.

  • TreeSet: This class implements the set interface, backed by a treemap instance. The class guarantees the elements will be in sorted order, and that add, remove, and contains operations are O(log(n)) operations.

  • WeakHashMap: A hashtable based map interface with “weak keys”. This means that the presence of a given key will not prevent the key from being discarded by the garbage collector. If ever there was a class that was not made for long term use, this would be it.

  • Vector: A dynamically resizeable array. This is a thread safe version of ArrayList. Vectors double in size when they fill up, rather than ArrayList’s 50% larger growth method.

  • Hi, Jon, how many types of container are there in general ?

  • This was great and very helpful. Thanks!

Comments are closed.