Hi, i'm working with jdk1.6. i'm having 2 enums as below: public enum c1 { a(1,2,3), b(1,2,3), c(1,2,3); ... }
public enum c2{ A, B, C; ... }
now from test class i want to create a hashmap with key from enum c1, value from enum c2.
Please help me: my peice of code is: public class test { HashMap<c1, c2> mapping = new HashMap<c1, c2>(); mapping.put(c1.a, c2.A); mapping.put(c1.b, c2.B); mapping.put(c1.c, c2.C); } this is not working... any ideas how to make this work...
You may want to change from HashMap to EnumMap. That class has been built especially for enumerations. It uses the enum ordinals for lookups instead of the hash codes.