Need of EnumSet / EnumMap over generified Set / Map

EnumSet/EnumMap can be created by specifying the defined enum to produce set/map instance as shown in below sample code.

So far I read, difference between EnumSet/EnumMap with that of Set/Map is that we cannot add objects other than the specified Enum in the EnumSet/EnumMap.

If this is the case, then just the generified Set/Map itself will be enough, isn't it?

Please find the EnumSet/EnumMap and their respective generified Set/Map as follows,

enum Value {



public class Sample {

public static void main(String args[]) {

EnumSet enumSet = EnumSet.of(Value.VALUE_1);

Set enumGenerifiedSet = new HashSet();


EnumMap enumMap...

Read More »

By: StackOverFlow - 5 days ago

Related Posts