Collection framework is heart of the Java Programming language. Collections in java is used in most of the application. This post will explain about Java Collections Framework in details.
Collections in Java
The Java Collections Framework standardizes the way in which groups of objects are handled by your programs. Collections were not part of the original Java release, but were added by J2SE 1.2. Prior to the Collections Framework, Java provided ad hoc classes such as Dictionary, Vector, Stack, and Properties to store and manipulate groups of objects.
The Collections Framework was designed to meet several goals.
- The framework had to be high-performance. The implementations for the fundamental collections (dynamic arrays, linked lists, trees, and hash tables) are highly efficient.
- The framework had to allow different types of collections to work in a similar manner and with a high degree of interoperability.
- Extending and/or adapting a collection had to be easy.
All the interfaces, classes and algorithms of collection framework are available in java.util package. Java Collections Framework consists of following parts:
Interfaces: The Collections Framework defines several core interfaces. Collection is the root interface of Collection Framework. It is on the top of the collection hierarchy.
Interface | Description |
---|---|
Collection | Enables you to work with groups of objects; it is at the top of the collections hierarchy. |
Deque | Extends Queue to handle a double-ended queue. |
List | List Extends Collection to handle sequences (lists of objects). |
NavigableSet | Extends SortedSet to handle retrieval of elements based on closest-match searches. |
Queue | Extends Collection to handle special types of lists in which elements are removed only from the head. |
Set | Extends Collection to handle sets, which must contain unique elements. |
SortedSet | SortedSet Extends Set to handle sorted sets. |
In addition to collection interfaces, collection also use the Comparator, RandomAccess, Iterator, ListIterator interfaces.
Comparator defines how two objects compared. Iterator, ListIterator, and Spliterator(introduced in JDK 8) enumerate the objects within a collection. By implementing RandomAccess, a list indicates that it supports efficient, random access to its elements.
Collection provides greatest flexibility in their use, collection interface allow some method to modify the content of a collection. Collections that support these method called modifiable. Collections that do not allow their contents to be changed are called unmodifiable. If an attempt is made to use one of these methods on an unmodifiable collection, an UnsupportedOperationException is thrown. All the built-in collections are modifiable.
No comments :
Post a Comment