Collection Basics 


                     Collection is a group of object. Collection is like containers that group multiple items in a single unit. List, Set and Map are the popular interfaces. Java Collection framework can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.

Java Collections framework has following benefits: 

1. Reduced Development Effort:

It comes with almost all common types of collections and useful methods to iterate and manipulate the data. So we can concentrate more on business logic rather than designing our collection APIs. 

2. Increased Quality: 

Using core collection classes that are well tested increases our program quality rather than using any home developed data structure. 

3. Reusability 

4. Interoperability 

 

Collection Interface-

                   This is the root of the collection hierarchy. A collection represents a group of objects known as its elements. The Java platform doesn’t provide any direct implementations of this interface. 

The interface has methods to tell you how many elements are in the collection (size(), isEmpty() ), to check whether a given object is in the collection (contains() ), to add and remove an element from the collection (add (), remove() ), and to provide an iterator over the collection (iterator()).

Collection interface also provides bulk operations methods that work on entire collection – containsAll(), addAll(), removeAll(), retainAll(), clear(). 

The toArray() methods are provided as a bridge between collections and older APIs that expect arrays on input.

 

Iterator Interface : Iterator interface provides methods to iterate over any Collection. We can get iterator instance from a Collection using iterator method. Iterator takes the place of Enumeration in COLLECTION Chapter 8 FULL STACK JAVA DEVELOPER 2 the Java Collections Framework. Iterators allow the caller to remove elements from the underlying collection during the iteration. Iterators in collection classes implement Iterator Design Pattern. 

List Interface:  List is an insertion ordered collection and can contain duplicate elements. You can access any element from its index. List is more like array with dynamic length. List is one of the most used Collection type. ArrayList and LinkedList are implementation classes of List interface.