Collections and arrays are similar in that they both hold references to objects and they can be managed as a group.
Collections can grow and shrink in size automatically when objects are added or removed.
Collections cannot hold primitive data types such as int, long, or double.
This can be considered an advantage of generic objects such as Collection when compared to arrays, because under circumstances, using the generic Collection instead of an array prevents run time exceptions by instead throwing a compile-time exception to inform the developer to fix the code.
If the developer attempts to add a String to this Long[] object, the java program will throw an ArrayStoreException.
[8][better source needed] The collections framework was designed and developed primarily by Joshua Bloch, and was introduced in JDK 1.2.
It reused many ideas and classes from Doug Lea's Collections package, which was deprecated as a result.
[6] Sun Microsystems chose not to use the ideas of JGL, because they wanted a compact framework, and consistency with C++ was not one of their goals.
[9][better source needed] Doug Lea later developed a concurrency package, comprising new Collection-related classes.
Lists are finite collections where it can store the same value multiple times.
There are several concrete classes that implement List, including AbstractList and all of its corresponding subclasses, as well as CopyOnWriteArrayList.
The direct subclasses of AbstractList class include AbstractSequentialList, ArrayList and Vector.
Whenever functions specific to a List are required, the class moves the elements around within the array in order to do it.
This is an example of a violation of the composition over inheritance principle in the Java platform libraries, since in computer science, a vector is generally not a stack.
[17] The java.util.Queue interface defines the queue data structure, which stores elements in the order in which they are inserted.
The direct subclasses of AbstractQueue class include ArrayBlockingQueue, ConcurrentLinkedQueue, DelayeQueue, LinkedBlockingDeque, LinkedBlockingQueue.
[21] Safe publication usually requires synchronization of the publishing and consuming threads.
There are several implementations of the Set interface, including AbstractSet and its subclasses, and the final static inner class ConcurrentHashMap.KeySetView
[14] Direct subclasses of AbstractSet include ConcurrentSkipListSet, CopyOnWriteArraySet, EnumSet, HashSet and TreeSet.
This bit field representation enables the developer to make efficient set-based operations and bitwise arithmetic such as intersection and unions.
[30] A recommended alternative approach is to use an EnumSet, where an int enum is used instead of a bit field.
[30] This approach uses an EnumSet to represent the set of values that belong to the same Enum type.
[30] Since the EnumSet implements the Set interface and no longer requires the use of bit-wise operations, this approach is more type-safe.
[30] After the introduction of the EnumSet, the bit field representation approach is considered to be obsolete.
It provides improved concurrency in many situations by removing the need to perform synchronization or making a copy of the object during iteration, similar to how CopyOnWriteArrayList acts as the concurrent replacement for a synchronized List.
The floor(E e), ceiling(E e), lower(E e), and higher(E e) methods find an element in the set that's close to the parameter.
[14] The direct subclasses of AbstractMap class include ConcurrentSkipListMap, EnumMap, HashMap, IdentityHashMap, TreeMap and WeakHashMap.
[36] This is because EnumMap internally uses an array, with implementation details completely hidden from the developer.
[37] LinkedHashMap extends HashMap by creating a doubly linked list between the elements, allowing them to be accessed in the order in which they were inserted into the map.
The ConcurrentHashMap uses a completely different locking strategy to provide improved scalability and concurrency.