| FazBrowse Wikipedia Viewer | Main Page | | |
| Viewing: https://en.wikipedia.org/wiki/Java_collections_framework |
The Java collections framework is a set of classes and interfaces that implement commonly reusable collection data structures (collections).
Although referred to as a framework, it works in a manner of a library. The collections framework provides both interfaces that define various collections and classes that implement them.
java.lang.Long, or Collection instead of an array prevents run time exceptions by instead throwing a compile-time exception to inform the developer to fix the code. For example, if a developer declares an Long[] instance with a certain capacity, no compile-time exception will be thrown. If the developer attempts to add a ArrayStoreException. On the other hand, if the developer instead declared a new instance of a "},"parts":[{"template":{"target":{"wt":"code","href":"./Template:Code"},"params":{"1":{"wt":"Collection<Object>"}},"i":0}}]}'>Collection<Object> as "},"parts":[{"template":{"target":{"wt":"code","href":"./Template:Code"},"params":{"1":{"wt":"ArrayList<Long>"}},"i":0}}]}'>ArrayList<Long>, the Java compiler will (correctly) throw a compile-time exception to indicate that the code is written with incompatible and incorrect type, thus preventing any potential run-time exceptions.The developer can fix the code by instantianting "},"parts":[{"template":{"target":{"wt":"code","href":"./Template:Code"},"params":{"1":{"wt":"Collection<Object>"}},"i":0}}]}'>Collection<Object> as an "},"parts":[{"template":{"target":{"wt":"code","href":"./Template:Code"},"params":{"1":{"wt":"ArrayList<Object>"}},"i":0}}]}'>ArrayList<Object> object. If the code is using Java SE7 or later versions, the developer can instantiate "},"parts":[{"template":{"target":{"wt":"code","href":"./Template:Code"},"params":{"1":{"wt":"Collection<Object>"}},"i":0}}]}'>Collection<Object> as an "},"parts":[{"template":{"target":{"wt":"code","href":"./Template:Code"},"params":{"1":{"wt":"ArrayList<>"}},"i":0}}]}'>ArrayList<> object by using the diamond operatorCollections are generic and hence reified, but arrays are not reified.
Collection implementations in pre-JDK 1.2 versions of the Java platform included few data structure classes, but did not contain a collections framework. The standard methods for grouping Java objects were via the array, the Vector, and the Hashtable classes, which unfortunately were not easy to extend, and did not implement a standard member interface.add(E e) and contains(E e) method checks if a specified element exists in the Collection.
The Collection interface is a subinterface of java.util.Iterator to scan all of the elements in the Collection.
Collection is generic. Any Collection can store any String objects. No casting is required when using the AbstractList and all of its corresponding subclasses, as well as AbstractList class include Vector.
java.util.ArrayList class implements the List as an array. Whenever functions specific to a List are required, the class moves the elements around within the array in order to do it.
The Stack classedit
The java.util.Stack. The Stack offers methods to put a new object on the Stack (method push(E e) and empty()), and a method to search the Stack for an item and discover how far it is from the top (CopyOnWriteArrayList extends the CopyOnWriteArrayList should not be used.
However synchronization can incur a performance overhead. For scenarios where synchronization is not mandatory, then the java.util.Queue interface defines the queue data structure, which stores elements in the order in which they are inserted. New additions go to the end of the line, and elements are removed from the front. It creates a first-in first-out system. This interface is implemented by java.util.LinkedList, Queue implementationsedit
Note that AbstractCollection but do not extend any other abstract classes such as PriorityQueue classedit
The java.util.PriorityQueue class implements java.util.Queue, but also alters it. PriorityQueue has an additional ConcurrentLinkedQueue classedit
The java.util.concurrent.ConcurrentLinkedQueue class extends ConcurrentLinkedQueue, the Java Collection Library guarantees that the element is safely published by allowing any thread to get the element from the collection. An object is said to be safely published if the object's state is made visible to all other thread at the same point in time. Safe publication usually requires synchronization of the publishing and consuming threads.
The BlockingQueue. It provides the same methods for insertion and removal with time limits for waiting for the insertion or removal to become possible. However, the interface also provides the flexibility of a Deque. Insertions and removals can take place at both ends. The blocking function is combined with the Deque function.
There are several implementations of the Set interface, including K and AbstractSet is a skeletal implementation for the ConcurrentSkipListSet, HashSet and EnumSet class extends EnumSet contains the static factory method EnumSet, where an int enum is used instead of a bit field. This approach uses an EnumSet implements the EnumSet, the bit field representation approach is considered to be obsolete.
The java.util.LinkedHashSet class extends CopyOnWriteArraySet is a concurrent replacement for a synchronized List. On the other hand, similar to SortedSet interfaceedit
The java.util.SortedSet interface extends the java.util.Set interface. Unlike a regular Set, the elements in a SortedSet are sorted, either by the element's last() methods respectively, and subsets can be created via minimum and maximum values, as well as beginning or ending at the beginning or ending of the SortedSet. The java.util.TreeSet class implements the SortedSet interface.
Maps are defined by the Maps are data structures that associate a key with an element. This lets the map be very flexible. If the key is the hash code of the element, the Map is essentially a Set. If it's just an increasing number, it becomes a list.
Examples of java.util.LinkedHashMap, and AbstractMap is an example of a skeletal implementation.
The direct subclasses of EnumMap, TreeMap and EnumMap extends EnumMap internally uses an array, with implementation details completely hidden from the developer. Hence, the EnumMap gets the type safety of a HashMap uses a hash table. The hashes of the keys are used to find the elements in various buckets. The LinkedHashMap extends TreeMapedit
LinkedHashMap, uses a red–black tree. The keys are used as the values for the nodes in the tree, and the nodes point to the elements in the Map.
The ConcurrentHashMap use a mechanism known as lock striping. This mechanism provides a finer-grained locking mechanism. It also permits a higher degree of shared access.
The "Java Collections Framework" (PDF). IBM. Archived from the original (PDF) on 2011-08-07.
| Sun, Oracle | |
|---|---|
| Platform | |
| Major third-party |
| Conferences | |
|---|---|
| Organizations | |
| People |
| View original on Wikipedia | Back | FazBrowse Home |