Collections and Maps: Basic and important

The java.util package contains one of Java’s most powerful subsystems: The Collections Framework. The Collections Framework is a sophisticated hierarchy of interfaces and classes that provide state-of-the-art technology for managing groups of objects.

You can perform following activity using Java collection framework:

  • Add objects to collection
  • Remove objects from collection
  • Search for an object in collection
  • Retrieve/get object from collection
  • Iterate through the collection for business specific functionality.

collection (lowercase c): It represents any of the data structures in which objects are stored and iterated over.
Collection (capital C): It is actually the java.util.Collection interface from which Set, List, and Queue extend.
Collections (capital C and ends with s): It is the java.util.Collections class that holds a pile of static utility methods for use with collections.


Lists:

The List interface extends Collection to define an ordered collection with duplicates allowed. The List interface adds position-oriented operations, as well as a new list iterator that enables the user to traverse the list bi-directionally. Lists interface can be implemented using ArrayList, LinkedList or vector 
Sets
The Set interface extends the Collection interface. It will make sure that an instance of Set contains no duplicate elements. The concrete class implements hashcode and equals methods to make sure uniqueness of objects. Sets  interface can be implemented using HashSet, LinkedHashSet and TreeSet.
Queues:
A queue is a first-in, first-out data structure. Elements are appended to the end of the queue and are removed from the beginning of the queue. In a priority queue, elements are assigned priorities. When accessing elements, the element with the highest priority is removed first.
Maps: Does not extend collections interface bu
A map is a container that stores the elements along with the keys. The keys are like indexes. In List, the indexes are integers. In Map, the keys can be any objects. A map cannot contain duplicate keys. Each key maps to one value. A key and its corresponding value from an entry, which is actually stored in a map. HashMap, HashTable,TreeMap and LinkedHashMap classes implement Map interface.



Comments

Popular Posts