I have a TreeMap defined like:
final TreeMap<ArrayList<String>,String> mymap = new TreeMap<ArrayList<String>,String>(comparator);
When I try to iterate over it like this:
Iterator iter = (Iterator) mymap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry entry = (Map.Entry) iter.next();
}
I am getting error message like The method hasNext() is undefined for the type ObjToIntMap.Iterator on the 2nd line and Multiple markers at this line
– Map.Entry is a raw type. References to generic type Map.Entry should be
parameterized on the 3rd line.
What is the source of this error, and how can I fix it?
Maybe you imported the wrong
Iteratorclass? Are you sure you have importedjava.util.Iteratorand no other class from an other package that is also namedIterator?If you imported the correct
Iteratorclass you can remove the typecast and add the generic type to the iterator: