Java 基础 HashMap + Iterator遍历集合

1.Iterator遍历集合
public static void main(String[] args){

    Map map = new HashMap();
    map.put("土耳其","热气球");
    map.put("中国","长城");
    map.put("法国","铁塔");
    Set keySet = map.keySet();
    Iterator  it = keySet.iterator();
    while (it.hasNext()){
     String key =   it.next();
     String value = map.get(key);
        System.out.println(key+"="+value);

    }

}

输出

土耳其=热气球
法国=铁塔
中国=长城

你可能感兴趣的:(java基础)