java - Iterating through a HashMap in a For Each style -


i want iterate through 'character' hashmap , grab of the'stat' objects using each loop. example want create function called 'showstats'. want able output 'stat' objects contained in 'character' hashmap. know how this?

hashmap<string, gameobject> character = new hashmap<string, gameobject>; character.put("health", new stat("health",10)); character.put("accuracy", new stat("accuracy",10)); character.put("strength", new stat("strength",10)); character.put("coins",new item("coins","your money")); character.put("head",new bodypart("head")); 

use values collection

for(gameobject gameobject : character.values()) {      if(gameobject instanceof stat) { } } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -