Top 10 Java Collections framework interview questions and answers

1.What are the differences between ArrayList and Vector ?



ArrayList is not synchronized

Vector is synchronized

ArrayList is not a legacy class

Vector  is a legacy class

ArrayList increase half size of its array size when it is resized

Vector increase the double the size of its array size when it is resized

ArrayList is not thread-safe

Vector is a thread-safe

2.What is the difference between the Iterator and ListIterator ?



Iterator is used to traverse the element in forward-direction only.

ListIterator is used to traverse the element in both forward and backward directions.

Iterator can use with Set,List and Queue

ListIterator can use only with List

Iterator allow only remove the element while traversing,not adding. 

ListIterator allow add,remove and modify the elements while traversing the elements.

3.What is the difference between the HashMap  and HashTable ?



HashMap is not synchronized

Hashtable is synchronised

HashMap allow one null key and multiple null values

HashTable does  not allow null key and null values.

It is very useful  for the non-threaded applications

It is very useful  for threaded applications.

It does not maintain insertion order that means it does not give the guarantee in which order elements are inserted ,output will be same order.  

HashTable is a legacy class

HashMap inheritance AbstractMap class

HashMap inheritance Dictionary class

4.What is the comparable and comparator interface ?

Comparable interface

Comparator interface

Comparable interface provides the single way of sorting ie on the  basis of only one element such as id,name or mobileNumber etc. 

Comparator interface provides multiple ways of sorting ie on the basis of multiple elements such as id,name or mobileNumber etc.

We can sort the element by the CompareTo( ) method.

We can sort the element by the Compare( ) method

Comparable interface is defined  in the java.lang package.

Comparator interface is defined in the java.util package 

Comparable affects the original class 

Comparator does not affect the original class

5.What do you mean by Collection framework in java ?

Java collections framework is the collections of classes and interfaces which is used to store and manipulate the groups of objects into a single unit.There are various classes such as ArrayList,LinkedList,Vector etc and interfaces such as Set,List  and Map etc

6.What is the difference between the Set ,List and Map interface ?


It does not maintain insertion order means it depends on implementation

It does not allow duplicate element

It allows the only single null values

It does not contain legacy class


It maintains the order means in which order elements are inserted,output will be in the same Order

It allows duplicate elements

It allows the many number of null values

It contains single legacy class


Map is used to store the value on the basis of key ie key-value pairs.

Map contains unique key

Map implemented class are HashMap,LinkedHashMap and TreeMap etc.

7.Write a program of storing five names using Map interface with new style.

Note:Here we will use the Map.entry( ) class which provides the two methods getKey( ) and getValue( ).

getKey( )=it is used to get key

getValue( )=It is used to  get value

import java.util.*;
import java.util.List;
import java.util.ArrayList;
public class HashMapExample
Public static void main(String[ ] args)
Map<Integer,String> obj=new HashMap<Integer,String>( );

//Traversing the elements

for(Map.entry map:obj.entrySet( ))
System.out.println(map.getkey( )+ “ “ +map.getValue( ));


1 suman

2 raj

3 ajay

4 rahul

5 kumar

8.How can you convert ArrayList to Array ?

We can convert ArrayList to Array using the “toArray( )”  method.

import java.util.*;
import java.util.List;
import java.util.ArrayList;

Public  class ArrayListToArray
Public static void main(String[]  args)
List<integer> list=new ArrayList<Integer>( );

Integer [ ] array=new Integer[list.size];

//Traversing the element
for(Integer a :array)
System.out.println(a+ “ “);






9.What is the difference between the Collection and Collections ?


Collection is an interface.

Collection provides some interfaces such as List,Set and Map etc.


Collections is  a class

Collections class contains some important methods such as Collections.sort( ) and Collections.synchronizedlist( ).

10.How we cam make collection thread-safe ?

Some methods are given below makes collection thread-safe




Thanks and Regards

Placement preparation


Hello Friends,I have written and developed this website because you can learn technology easily ,prepare for the placement and also for the any type of examination . By :Suman Kumar

Leave a Reply

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