Collection Types and features in Java. (Collection-1)

Types and features of Collection in Java.

The Collection is a root Interface which contains other Interfaces like List, Queue, Map and Set. These Interfaces further contains Classes or sub-interfaces.

Facts about Collection

All these Classes and Interfaces make a framework structure to create a list of objects(like String, Integer, etc). It also provides common methods/features to handle and manipulate these under various interfaces and classes.

  1. Accessible from java.util library.
  2. Some collections allow duplicate elements, some collections do not.
  3. Some collections are in an ordered way and some not.
  4. Only non-primitive data types can be used in these interfaces and classes to store data. Like String, Integer, etc.
  5. All these interfaces and classes use similar types of methods to manipulate data. Like add(), remove(), size() etc.
  6. Five main operations on Collection Addition, Insertion, deletion, retrieval and traversal can be performed.

Overview of widely used Collection Interfaces

In this chapter, I am summarizing all the Classes based on their interfaces, keypoints, and declaration. It will help you to get familiar with these classes. In later chapters, we will learn about each class individually.


  • Classes: Commonly used classes.
    • ArrayList
    • LinkedList
  • Key points:
    • Stores objects as a list of elements.
    • Any number of elements can be added to the list.
    • Ability to store similar as well as different types of elements to a single list.
    • It allows duplicate values in the list.
    • All the elements in the list remain in the same order in which we have added them even we add, remove, insert a new element in the list.
    • Each element has an integer type index value to locate in the list. like 0, 1, 2, 3 and so on.
    • Searching any specific value(element) in the list is slow.
    • Searching for any specific value(element) using the index number is fast on the list.
    • Traversing the list is faster.
    • Sorting the list is possible.
    • Use ArrayList, if you want to add/remove data from the end of the list.
    • Use LinkedList, if you want to add/remove data in-between the list.
  • Declarations:
List<String> tempList = new ArrayList<String>();
List<Integer> tempList = new ArrayList<Integer>(); 
List mixedArray=new ArrayList<>();
List<String> tempList = new LinkedList<String>();
List<Integer> tempList = new  LinkedList<Integer>(); 
List mixedArray=new  LinkedList<>(); 


  • Classes: Commonly used classes.
    • HashSet
    • TreeSet
    • LinkedHashSet
  • Key points:
    • Duplicates elements are not allowed in Sets.
    • Indexing of elements in Set classes not available like Lists.
    • Very fast to search for any specific item(element) in the set.
    • HashSet is not ordered in nature.
    • TreeSet remains sorted in the natural order in ascending order either it is integer or string.
    • TreeSet uses the tree algorithm internally.
    • LinkedHashSet, elements remain in the order they added.
    • LinkedHashSet uses LinkedList internally to process the data.
  • Declarations:
Set set1=new HashSet<>();
Set set2=new HashSet<String>();
Set<String>  set3=new HashSet<String>();
HashSet set4=new HashSet<>();


  • Classes: Commonly used classes.
    • HashMap
    • TreeMap
    • LinkedHashMap
  • Key points:
    • Elements stored in key-value pair
    • Key can be of any data type
    • The duplicate entry of key is allowed, but in real scenarios, it is not ideal.
    • Searching any value using the key is very fast.
    • The traversing of the map using values is a slow process
    • In HashMap, keys are not in order. They can change runtime.
    • In TreeMap, keys are sorted in the natural order.
    • LinkedHashMap, Keys remain in the order they have been added.
  • Declarations:
Map map1=new HashMap<>();
Map map2=new HashMap<String, String>();
Map<String, String> map3=new HashMap<String, String>();   
Map<Integer, String> map4=new HashMap<Integer, String>();


  • Class: Commonly used classes.
    • ArrayBlockingQueue
    • LinkedList
    • PriorityQueue
  • Key points:
    • As in real life, elements added from one end and removed from another end. Like FIFO, First In First Out concept.
    • It can store any type of non-primitive data type.
    • Unlike other collections, we have to define the limit of the elements which can be stored in a queue.
    • Indexing of elements not available.
    • Items(elements) can only be added after the last added item in the Queue.
    • Elements can only be removed from the Head of the Queue. It cannot be added or removed from any particular place. This means from the first element added in the queue.
  • Declarations:
Queue queue1=new ArrayBlockingQueue<>(3); 
Queue q2=new ArrayBlockingQueue<String>(3);
Queue<String> q3=new ArrayBlockingQueue<String>(3);
ArrayBlockingQueue<Integer> q4=new ArrayBlockingQueue<Integer>(4);


Computer Basics:

Java Basics:

Java Collection:

Java File Handling:

OOPs Concept:

Java Question And Answer:

Java Programs:

Selenium Tutorials:



Leave a Reply

Your email address will not be published. Required fields are marked *

Site Statistics

  • Users online: 0 
  • Visitors today : 2
  • Page views today : 2
  • Total visitors : 51,167
  • Total page view: 70,434

   YouTube ChannelQuora

            Ashok Kumar is working in an IT Company as a QA Consultant. He has started his career as a Test Trainee in manual testing in August 2010. Then he moves towards the automation testing after 4 years. He started learning JAVA and Selenium by self to get the knowledge of automation.

       While learning these tools and working on multiple projects, he found that sometimes people get stuck in live scenarios in their project and they have to do lots of RnD to get out of it. So he decided to start blogging only for such scenarios, where anyone facing any problem in their project, can ask any question or give a solution or you can say an alternate solution to achieve the goal successfully.

Later on, he observed that some people want to learn Java but they have few questions in their mind like how to start Java, whether we should go for the online or offline course. So he started writing tutorials on Java, Jira, Selenium, Excel etc.