Previous to Java 2, Java offered ad hoc classes such as lexicon, Vector, heap, and Properties to amass and influence groups of entities. Although these objects were useful, they required a middle, unifying theme. Thus, the technique that you exercised Vector was diverse from the means that you utilized Properties.
The compilations structure was planned to meet numerous goals, such as −
Towards this end, the frame of the complete collection is meant around a set of standard lines. Numerous typical implementations such as LinkedList, HashSet, and TreeSet, of these lines, are if you might employ as-is and you may implement your possess collection if you decide.
A compilations frame is a combined architecture for instead of and manipulating compilations. Entire collections frameworks enclose the subsequent −
In addition to collections, the framework describes quite a few map lines and classes. Maps amass key/worth pairs. Although maps are not sets in the correct utilization of the expression, yet they are copiously included with collections.
The collections framework defines various interfaces. This section offers an overview of every interface −
Sr.No. | Interface & Description |
---|---|
1 | The Collection Interface This enables you to work with groups of objects; it is at the top of the collections hierarchy. |
2 | The List Interface This extends Collection and an instance of List stores an ordered collection of elements. |
3 | The Set This extends Collection to handle sets, which must contain unique elements. |
4 | The SortedSet This extends Set to handle sorted sets. |
5 | The Map This maps unique keys to values. |
6 | The Map.Entry This describes an element (a key/value pair) in a map. This is an inner class of Map. |
7 | The SortedMap This extends Map so that the keys are maintained in ascending order. |
8 | The Enumeration This is legacy interface defines the methods by which you can enumerate (obtain one at a time) the elements in a collection of objects. This legacy interface has been superseded by Iterator. |
Java applies a set of typical collection classes that realize Collection interfaces. A few of the classes supply filled executions that can be utilized as-is and others are conceptual classes, offering skeletal implementations that are employed as beginning points for developing tangible collections.
The typical collection classes are abridged in the subsequent table −
Sr.No. | Class & Description |
---|---|
1 | AbstractCollection Implements most of the Collection interface. |
2 | AbstractList Extends AbstractCollection and implements most of the List interface. |
3 | AbstractSequentialList Extends AbstractList for use by a collection that uses sequential rather than random access of its elements. |
4 | LinkedList Implements a linked list by extending AbstractSequentialList. |
5 | ArrayList Implements a dynamic array by extending AbstractList. |
6 | AbstractSet Extends AbstractCollection and implements most of the Set interface. |
7 | HashSet Extends AbstractSet for use with a hash table. |
8 | LinkedHashSet Extends HashSet to allow insertion-order iterations. |
9 | TreeSet Implements a set stored in a tree. Extends AbstractSet. |
10 | AbstractMap Implements most of the Map interface. |
11 | HashMap Extends AbstractMap to use a hash table. |
12 | TreeMap Extends AbstractMap to use a tree. |
13 | WeakHashMap Extends AbstractMap to use a hash table with weak keys. |
14 | LinkedHashMap Extends HashMap to allow insertion-order iterations. |
15 | IdentityHashMap Extends AbstractMap and uses reference equality when comparing documents. |
The AbstractCollection, AbstractSet, AbstractList, AbstractSequentialList, and AbstractMap classes provide skeletal implementations of the core collection interfaces, to minimize the effort required to implement them.
The following legacy classes are defined by java.util has been discussed in the previous chapter −
Sr.No. | Class & Description |
---|---|
1 | Vector This implements a dynamic array. It is similar to ArrayList, but with some differences. |
2 | Stack Stack is a subclass of Vector that implements a standard last-in, first-out stack. |
3 | Dictionary Dictionary is an abstract class that represents a key/value storage repository and operates much like Map. |
4 | Hashtable Hashtable was part of the original java.util and is a concrete implementation of a Dictionary. |
5 | Properties Properties is a subclass of Hashtable. It is used to maintain lists of values in which the key is a String and the value is also a String. |
6 | BitSet A BitSet class creates a special type of array that holds bit values. This array can increase in size as needed. |
The collections frame classifies some algorithms that can be useful to collections and maps. These algorithms are described as motionless methods within the Collections class.
Several of the methods can throw a ClassCastException, which occurs when an attempt is made to compare incompatible types, or an UnsupportedOperationException, which occurs when an attempt is made to modify an unmodifiable collection.
Collections define three static variables: EMPTY_SET, EMPTY_LIST, and EMPTY_MAP. All are immutable.
Sr.No. | Algorithm & Description |
---|---|
1 | The Collection Algorithms Here is a list of all the algorithm implementations. |
Frequently, you will desire to cycle throughout the constituents in an anthology. For instance, you might desire to show each element.
The easiest technique to do this is to use an iterator, which is a thing that equipment either the Iterator or the ListIterator line.
Iterator allows you to round through a compilation, getting or removing elements. ListIterator expands Iterator to permit bidirectional traversal of an inventory and the change of basics.
Sr.No. | Iterator Method & Description |
---|---|
1 | Using Java Iterator Here is a list of all the methods with examples provided by Iterator and ListIterator interfaces. |
Both TreeSet and TreeMap store basics in a classed order. But, it is the comparator that describes exactly what ensued order means.
This border lets us class a known collection any figure of dissimilar ways. Also, this line can be utilized to sort any case in points of any class (even classes we never modify).
Sr.No. | Iterator Method & Description |
---|---|
1 | Using Java Comparator Here is a list of all the methods with examples provided by Comparator Interface. |
The Java compilations structure offers the programmer admittance to prepackaged information arrangements as well as to algorithms for manipulating them.
A set is an article that can clutch orientations to other entities. The collection lines state the procedures that can be executed on each type of anthology.
The classes and lines of the framework of the album are in wrap-up java.util.
Here at Intellinuts, we have created a complete Java tutorial for Beginners to get started in Java.