I searched this question and found answers that used the Map.Entry like here, however the getValue() method returned an Object object instead of the type of object in the map. Like in the example below, I need it to return a User object so I can use a method from that class. When I tried using the while loop below however, it never leaves the loop. I was wondering the correct way to do this.
Map<String, User> users = new LinkedHashMap<String, User>();
users.put(name, user);
while(users.values().iterator().hasNext()){
currentUser = users.values().iterator().next();
currentUser.someMethod();
}
Map.Entryway is the correct way when you need both keys and values. IfgetValue()'s compile-time return type is anObjectthen you are likely missing type parameters on theMap.Entrydeclaration.