Why does not it work? The error constantly gets out:
at java.util.HashMap$HashIterator.nextEntry(Unknown Source) at java.util.HashMap$KeyIterator.next(Unknown Source)
Here is the code itself:
HashMap<Age, Integer> mapFromAgeToValues = new HashMap<Age, Integer>(); mapFromAgeToValues.put(Age.AGE1, 1); mapFromAgeToValues.put(Age.AGE2, 11); mapFromAgeToValues.put(Age.AGE3, 111); mapFromAgeToValues.put(Age.AGE4, 1333); HashSet<Age> example = new HashSet<Age>(); example.add(Age.AGE2); Integer r = 0; Iterator it = example.iterator(); while ( it.hasNext() ){ if ( mapFromAgeToValues.containsKey(it.next()) ){ r += mapFromAgeToValues.get(it.next()); } } out.println(r);
Age - It's just enum