Java Collection Framework is one of the most important and widely used framework by Java Developers. Java Collection Framework is a collection or can be called as a container that groups multiple elements together to store, manipulate and communicate the aggregated data.
We can also say that the Java Collection Framework is an unified architecture to store and manipulate collections. The Java Collection Framework contains:
- Interfaces
- Implementation
- Algorithms
How Java Collections Framework benefits developers ?
The Java Collection Framework provides the below given advantages:
- Java Collections Framework provides useful data structures and algorithms which helps in Acatlán de Osorio reducing the overall programming effort
- Java Collections Framework provides interfaces which are interchangeable based on collections implementation and provides high quality data structures and algorithms which http://czechinthekitchen.com/2012/03/23/beef-and-dumplings-with-dill-sauce/ provides fast program execution
- Java Collections Framework can be used among non related API integration using collections and thus allows interoperability
- Java Collections Framework reduces the overall effort to design new APIs
- The newly added algorithms reuses the Current Collections Framework interfaces and implementation
Interfaces in Java Collection Framework
The interfaces in the Java Collection Framework define the baseline to encapsulate different types of collections.
The below given diagram depicts the collection interfaces in java. Collections is the root hierarchy and is used by all the group of objects i.e. elements of the collections. The Collections interface is not provides for the implementation although other collection interfaces use it internally to pass the collections during run time implementation
Although Map has been shown as part of Collections but it is not a pure collection interface.
Methods in Java Collection Framework
The below given are the methods supported by Java Collection Framework
Method | Description |
---|---|
public boolean add(E e) | allows to insert an element in collection |
public boolean addAll(Collection<? extends E> c) | allows to insert the specified collection elements in the invoking collection |
public boolean remove(Object element) | allows to remove an element from the collection |
public boolean removeAll(Collection<?> c) | allows to remove all the elements from the collection |
default boolean removeIf(Predicate<? super E> filter) | allows to remove all the elements of the collection if given condition is justified |
public boolean retainAll(Collection<?> c) | allows to retain all the elements of collection based on given condition |
public int size() | returns the collection element count |
public void clear() | clears all the collection elements |
public boolean contains(Object element) | allows to search an element in collection |
public boolean containsAll(Collection<?> c) | allows to search an element in collection based on given condition |
public Iterator iterator() | returns an iterator |
public Object[] toArray() | allows to convert collection into an array |
public <T> T[] toArray(T[] a) | returns the array after converting collection into an array |
public boolean isEmpty() | depicts if collection is empty |
default Stream<E> parallelStream() | returns parallel stream with collection as source |
default Stream<E> stream() | returns sequential Stream with collection as source |
default Spliterator<E> spliterator() | creates Spliterator for the elements in the collection |
public boolean equals(Object element) | allows to compare two collections. |
public int hashCode() | It returns collection hash code number |