Collections in java is a framework. It is are one of the most commonly reusable data structures. Collection framework provides many interfaces (Set, List, Queue, Deque etc.) and classes ArrayList, Vector, LinkedList, PriorityQueue, HashSet, LinkedHashSet etc.
Java collections are one of the most commonly used data-structures by all Java professionals. But are you using the right collection class that would best suits your need. Most programmers usually use Vectors, ArrayList, HashMap or the Hashtable. There are many other collection classes available with the JDK that you can use instead of re-inventing logic to suite your needs.
We will be trying to understand the different types of classes and when each Collection class could be used. We wouldn’t be looking into the implementation details of any collection, for that please refer the latest Java Collection API docs.
The Core Collection Framework Interfaces
The core collection frameworks are depicted in the following image.
The main type of collections are:
Maps are not an integral part of the Collection framework, but they are still considered as Collection because of their capability to store and manipulate data as collection of objects.
Sorted Sets and Sorted Maps are basically a sorted version of Sets and Maps.
Hierarchy of Collection Framework
Let us see the hierarchy of collection framework.The java.util package contains all the classes and interfaces for Collection framework.
Goals for Java Collections:
The collections framework was designed to meet several goals.
Commonly used methods of Collection interface:
There are many methods declared in the Collection interface. They are as follows:
Iterator interface
Iterator interface provides the facility of iterating the elements in forward direction only.
Methods of Iterator interface
There are only three methods in the Iterator interface. They are:
References
http://www.janeve.me/articles/which-java-collection-to-use
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…