Prior to this java2,java offers ad hoc courses such as dictionaries, vectors, stacks and attributes (Dictionary, vector, stack,properties) to store and manipulate groups of objects. While these classes are very useful, they lack a central, unified theme. Therefore, the vectors used are in a different way from using properties.
The purpose of the collection framework is to meet several goals.
The framework must be high-performance. In the implementation of the basic set (dynamic array, linked list, tree, hash table) is efficient.
The framework has the interoperability of allowing different types of collections in a similar manner and height.
The set of extensions and/or adaptations must be easy.
For this purpose, the entire set of frames is designed around a standard set of interfaces. Several standard implementations are available, such as Linkedlist,hashset and TreeSet, which can be used as-is or to implement their own collections.
A collection framework is a unified architecture for representing and manipulating collections. All collection frames contain the following:
Interfaces: These are abstract data types that represent collections. Interfaces allow the collection of representative details to operate independently. In object-oriented languages, interfaces generally form a hierarchy.
Implementations, that is, classes: These are the concrete implementations of the collection interface. In essence, they are reusable data structures.
Algorithms: These are the objects that perform useful computational methods, such as searching and sorting, in which to implement the collection interface. is a polymorphic algorithm: that is, the same approach can be used in many different implementations of the appropriate collection interfaces.
In addition to the collection, the framework defines several mapped interfaces and classes. Maps store key/value pairs. Although the mappings are not used in the correct terminology collection, they are fully integrated with the collection.
Collection interface:
The collection framework defines several interfaces. This section provides an overview of each interface:
| SN |
interface and Description |
| 1 |
Collection interface This can work with object groups, which are at the top level of the collection hierarchy. |
| 2 |
List interface This expands an ordered collection of elements for an instance of the collection and list. |
| 3 |
Set This expands the collection to the processing collection, which must contain unique elements |
| 4 |
SortedSet This expands the collection to handle an ordered set |
| 5 |
Map This corresponds to the value of the unique key. |
| 6 |
Map.entry This shows the element in the map (a key/value pair). This is an internal map class. |
| 7 |
SortedMap Expand map maps so the keys remain in ascending order. |
| 8 |
Enumeration This is the traditional interface and method of defining the elements of an object collection through which it can enumerate (get one at a time). This traditional interface has been replaced by iterators. |
Collection class:
Java provides a set of collection classes that implement the collection interface standard. Some classes provide a sufficient implementation, which can be used as is, with other abstract classes, and provides a framework implementation that is used as a starting point for creating specific collections.
The standard collection classes are summarized in the following table:
| SN |
Class and Description |
| 1 |
Abstractcollection Implement most of the collection interfaces. |
| 2 |
Abstractlist Extend the abstractcollection and implement the list interface. |
| 3 |
Abstractsequentiallist The extension abstractlist is used for collections that are accessed by using their elements in order instead of randomly. |
| 4 |
LinkedList Implements a linked list by extending the abstractsequentiallist. |
| 5 |
ArrayList Implements a dynamic array by extending the abstractlist. |
| 6 |
Abstractset Extend the abstractcollection and implement most of the set interfaces. |
| 7 |
HashSet Extended Abstractset uses a hash table. |
| 8 |
Linkedhashset Expands hashset to allow insertion of sequential iterations. |
| 9 |
TreeSet Implements a set of stored in a tree. Extended Abstractset. |
| 10 |
Abstractmap Implement most map interfaces. |
| 11 |
HashMap Extended Abstractmap uses a hash table. |
| 12 |
TreeMap Extend the abstractmap with a tree. |
| 13 |
Weakhashmap Extended Abstractmap uses a hash table and weak keys. |
| 14 |
Linkedhashmap Expands HashMap to allow insertion of sequential iterations. |
| 15 |
Identityhashmap When you extend Abstractmap and use reference equality to compare documents. |
abstractcollection, Abstractset, Abstractlist, abstractsequentiallist and abstractmap class provides a framework implementation of the core collection interfaces to minimize the work required to implement them.
The following legacy classes, as defined in Java.util, have been discussed in previous tutorials:
| SN |
Class and Description |
| 1 |
Vector This implements the dynamic array. It is similar to ArrayList, but there are some differences. |
| 2 |
Stack A stack is a subclass of a vector that implements a standard last-in-first-out stack. |
| 3 |
Dictionary The dictionary represents a key/value repository that works much like the map abstract class. |
| 4 |
Hashtable Hashtable Hash table is a part of the original java.util, is a concrete implementation of a dictionary. |
| 5 |
Properties Properties is a subclass of a hash table. It is used to maintain a list of values where the key is a string and the value is also a string. |
| 6 |
BitSet The BitSet class creates a special type of array to hold the bit values. The size of this array can be increased as needed. |
Collection algorithm:
The collection framework defines several algorithms that can be applied to collections and mappings. These algorithms are defined as static methods in the collection class.
There are several ways to throw a classcastexception when it tries to compare incompatible types, or to throw a unsupportedoperationexception when it tries to modify a non-modifiable collection to occur.
A collection defines three static variables: Empty_set,empty_list and Empty_map. These are not to be changed.
| SN |
Algorithm and Description |
| 1 |
The Collection algorithms Here is a list of implementations of all the algorithms. |
How do I use iterators?
Typically, you want to iterate through the elements in the collection. For example, you might want to display each element.
The simplest way to do this is to use an iterator, which is an object that implements an iterator or Listiterator interface.
Iterators enable the ability to loop through collections, get or remove elements. The Listiterator extension iterator allows the decoration of lists and elements to traverse bidirectional.
| SN |
iterator method and description |
| 1 |
Using Java iterators The following is a list of all the instance methods provided with the Listiterator and interfaces of iterators. |
How do I use a comparator?
The storage elements for these two treeset and TreeMap are already in sort order. However, it is the comparator that defines their sort order device.
This interface allows us to sort all the quantities in a given set in different ways. In addition, this interface can be used for any class (even classes that we cannot modify) to sort on any instance.
| SN |
Comparator method and Description |
| 1 |
Using the Java Comparer Here is a list of all the methods that are provided by the comparator interface for the embodiment. |
Summarize:
The Java Collection Framework provides programmers with access to prepackaged data structures and algorithms for manipulating them.
A collection is an object that can hold references to other objects. The collection interface declares the actions that can be performed on each type of collection.
The classes and interfaces of the collection framework are in the Java.util package.
Java Collection Framework