FazBrowse Wikipedia Viewer | Main Page |
Search Wikipedia:
|
Viewing: https://en.wikipedia.org/wiki/Java_collections_framework

Java collections framework

Contents
History
        ArrayBlockingQueue, LinkedBlockingDeque, PriorityBlockingQueue. 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. BlockingQueue interface has the following direct sub-interfaces: BlockingQueue works like a regular Queue, but additions to and removals from the BlockingQueue are blocking. If take() which removes and gets the head of the BlockingQueue, and waits until the BlockingQueue is no longer empty if required. Double-ended queue (Queue interface. Deque allows insertions or removals to take place both at the front and the back. A Deque interface is implemented by java.util.ArrayDeque and java.util.LinkedList. java.util.Deque interface, giving it more flexibility. BlockingDeque interface
java.util.HashSet, Set interface implementationsedit 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. LinkedHashSet classedit 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. floor(E e), higher(E e) methods find an element in the set that's close to the parameter. Additionally, a descending iterator over the items in the Set is provided. As with SortedSet, java.util.TreeSet implements NavigableSet. java.util.SortedSet. SortedSet. For example it replaces a Map interfaces
        K) subMap(K fromKey, K toKey) method. SortedMap is implemented by java.util.TreeMap. ConcurrentMap interface

Diagram of the class and interface hierarchy of the Java collections frameworkJava collections framework class and interface hierarchy, excluding types in the java.util.concurrent package and a few other classes

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 operator

Collections are generic and hence reified, but arrays are not reified.

History

edit

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.

Vector class
edit

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

ArrayBlockingQueue, LinkedBlockingDeque, PriorityBlockingQueue.

Note that AbstractCollection but do not extend any other abstract classes such as PriorityQueue class

edit

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.

BlockingQueue interface has the following direct sub-interfaces: BlockingQueue works like a regular Queue, but additions to and removals from the BlockingQueue are blocking. If take() which removes and gets the head of the BlockingQueue, and waits until the BlockingQueue is no longer empty if required.

Double-ended queue (Queue interface. Deque allows insertions or removals to take place both at the front and the back. A Deque interface is implemented by java.util.ArrayDeque and java.util.LinkedList.

java.util.Deque interface, giving it more flexibility.

BlockingDeque interface
edit

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.

java.util.HashSet, Set interface implementations

edit

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.

LinkedHashSet class
edit

The java.util.LinkedHashSet class extends CopyOnWriteArraySet is a concurrent replacement for a synchronized List. On the other hand, similar to SortedSet interface

edit

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.

floor(E e), higher(E e) methods find an element in the set that's close to the parameter. Additionally, a descending iterator over the items in the Set is provided. As with SortedSet, java.util.TreeSet implements NavigableSet.

java.util.SortedSet.

SortedSet. For example it replaces a Map interfaces
edit

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 TreeMap

edit

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.

HashMap and is also a hash-based collection. However, there are a number of differences, such as the differences in the locking strategy they use.

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.

SortedMap. ConcurrentSkipListMap replaces a Map subinterfaces
edit

K) subMap(K fromKey, K toKey) method. SortedMap is implemented by java.util.TreeMap.

ConcurrentMap interface
edit

The "Java Collections Framework" (PDF). IBM. Archived from the original (PDF) on 2011-08-07.

  • ↑ get</code> and <code>put</code> methods.''"}},"i":0}}]}'/>Becker, Dan (November 1, 1998). "Get started with the Java Collections Framework". JavaWorld. Retrieved 2020-07-13. Before Collections made its most welcome debut, the standard methods for grouping Java objects were via the array, the Vector, and the Hashtable. All three of these collections have different methods and syntax for accessing members: arrays use the square bracket ([]) symbols, Vector uses the elementAt method, and Hashtable uses get and put methods.
  • 1 2 Vanhelsuwé, Laurence (June 1, 1997). "Need a good set of abstract data structures? ObjectSpace's JGL packs a punch!". JavaWorld. Retrieved 2020-07-13. As with Java itself, the Java Generic Library borrows heavily from the C++ camp: It takes the best from C++'s STL, while leaving the C++ warts behind. Most C++ programmers today will know of their STL, but few are managing to exploit its potential.
  • ↑ "Iterable (Java Platform SE 7)". Docs.oracle.com. 2013-06-06. Retrieved 2013-08-16.
  • Bloch 2018, pp. 117–122, Chapter §5 Item 26: Don't use raw types.
  • 1 2 3 Bloch 2018, pp. 99–103, Chapter §4 Item 20: Prefer interfaces to abstract classes.
  • ↑ "BlockingQueue (Java Platform SE 7)". Docs.oracle.com. 2013-06-06. Retrieved 2013-08-16.
  • ↑ Bloch 2018, pp. 325–329, Chapter §11 Item 81: Prefer concurrency utilities to wait and notify.
  • 1 2 Goetz et al. 2006, p. 92, §5.3.3 Deques and work stealing.
  • ↑ "BlockingDeque (Java Platform SE 7)". Docs.oracle.com. 2013-06-06. Retrieved 2013-08-16.
  • 1 2 3 Bloch 2018, pp. 5–9, Chapter §5 Use EnumSet instead of bit fields.
  • 1 2 3 4 5 6 7 8 9 10 11 Bloch 2018, pp. 169–170, Chapter §5 Use EnumSet instead of bit fields.
  • ↑ Goetz et al. 2006, pp. 86–89, §5.2.3 CopyOnWriteArrayList.
  • ↑ "Set (Java Platform SE 7)". Docs.oracle.com. 2013-06-06. Retrieved 2013-08-16.
  • 1 2 Goetz et al. 2006, pp. 84–85, §5.2 ConcurrentCollections.
  • 1 2 3 Bloch 2018, pp. 171–175, Chapter §6 Item 36: Use EnumMap instead of ordinal indexing.
  • 1 2 3 4 5 6 7 Goetz et al. 2006, pp. 85–86, §5.2.1 ConcurrentHashMap.
  • 1 2 3 Bloch 2018, pp. 199–202, Chapter §44 Favor the use of standard functional interfaces.
  • ↑ "NavigableMap (Java Platform SE 7)". Docs.oracle.com. 2013-06-06. Retrieved 2013-08-16.
  • ↑ Goetz, Brian; Peierls, Tim; Bloch, Joshua; Bowbeer, Joseph; Holmes, David; Lea, Doug (2006). Java Concurrency in Practice. Addison Wesley. ISBN 0-321-34960-1. OL 25208908M.
  • The Wikibook Java Programming has a page on the topic of: Collections

    Platforms
    Technologies
    Sun, Oracle
    Platform
    Major
    third-party
    HistoryPlatform
    languages
    Community
    Conferences
    Organizations
    People

    View original on Wikipedia | Back | FazBrowse Home