collection framework

Sorting using Comparable Interface

Posted on Updated on

The Comparable interface is used by the Collection.sort() method and the java.util.Array.sort() method to sort Lists and array of objects, respectively. To implement Comparable, a class must implement a single method, compareTo().  Read the rest of this entry »

Sort an Array using Comparator

Posted on Updated on

Comparator is an interface which comes under java.util package is useful to impose a total ordering on a collection of elements (Objects) of an array into ascending or descending order.

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 »

EnumMap in Java

Posted on Updated on

EnumMap is specialized Map implementation designed and optimized for using Java Enum as key. EnumMap in Java is added on JDK  5 release. There are some similarities as well as differences between EnumMap and HashMap which you can find hereFollowings are the features of EnumMap. Read the rest of this entry »