Collection Framework

HashMap vs ConcurrentHashMap

Posted on Updated on

ConcurrentHashMap was introduce with JDK1.5 release to replace legacy class Hashtable. In multithreaded environment ConcurrentHashMap performs better as compared to Hashtable and Synchronized Map as well. All methods of Hashtable are synchronized which makes them quite slow due to contention if a number of thread increases. While ConcurrentHashMap is specially designed for concurrent uses which by default allows 16 threads to simultaneously read and write from map without any external synchronization. Read the rest of this entry »

ArrayList vs Vector

Posted on Updated on

Vector is legacy class which is available with Java before collection framework comes into picture while ArrayList was introduce with collection framework. There are some basic differences between ArrayList and Vector as well as few similarities. It is very common to ask question around ArrayList and Vector in interviews. Also if we know the differences and similarities between ArrayList and Vector, it will be easier for us to select one of these while writing our code. Read the rest of this entry »

HashMap vs EnumMap

Posted on Updated on

EnumMap was introduced in Java along with JDK 5 updates which is specialized Map implementation designed and optimized for using Java Enum as key. Java is having HashMap and lots of other concrete implementation of Map interface. So it is natural to ask question around EnumMap and other maps in interview. Most popular in all of these are HashMap vs EnumMap. Here we will be discussing differences and similarities of these two maps. Read the rest of this entry »

Collection Framework Interview Questions – Set 2

Posted on Updated on

Hello Folks, welcome back to Collection Framework Interview Questions – Set 2. If you missed to visit the set 1 please click on below link.

Collection Framework Interview Questions Set 1

1). How to retrieve elements from Collections ?

There are following way to traverse/retrieve the elements from Collections Read the rest of this entry »