Hash
import java.util.Collection; import java.util.HashMap; import java.util.Iterator; public class HashDemo { public static void main(String[] args){ HashMap<String,Integer> hs=new HashMap<String,Integer>(); hs.put("a",1); hs.put("b", 2); hs.put("c", 3); /*Collection collection=hs.values(); Iterator iter=collection.iterator(); while(iter.hasNext()){ //System.out.println(iter.next()); }*/ //也可以用for循环 for( Integer value:hs.values()){ System.out.println(value); } } }
import java.util.EnumMap; import java.util.Map; enum Action {True_Left,True_Right,Shoot} public class TreeMap { public static void main(String[] args) { Map<Action,String> map=new EnumMap<Action,String>(Action.class); map.put(Action.True_Left, "向左转"); map.put(Action.True_Right,"向右转"); map.put(Action.Shoot, "射击"); for(Action action:Action.values()){ System.out.println(action); } } }