roomCharacters is a HashMap of keys and values (String keys and Character objects).
I need to return a Character from the collection. I have used an Iterator to simply return the first Character it finds, when the method is called.
public Character getCharacter()
{
Iterator<HashMap.Entry<String, Character>> it = roomCharacters.entrySet().iterator();
if (it.hasNext())
{
HashMap.Entry pair = (Map.Entry)it.next();
return pair.getValue();
}
}
But it fails to compile:
incompatible types: java.lang.Object cannot be converted to Character
Clearly I've misunderstood something or missed a step. Please advise and explain where I'm going wrong.