import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
public class MapTest {
public static void main(String[] args) {
Map map = new HashMap();
map.put("1", "gao");
map.put("2", "zhang");
map.put("3", "li");
map.put("4", "wang");
System.out.println(map);
//遍历value
Iterator it = map.values().iterator();
while(it.hasNext()){
System.out.println(it.next());
}
System.out.println("--------------------------------");
//根据key遍历value
Iterator it2 = map.keySet().iterator();
while(it2.hasNext()){
System.out.println(map.get(it2.next()));
}
System.out.println("--------------------------------");
//遍历entry
Iterator<Map.Entry<String, String>> it3 = map.entrySet().iterator();
while(it3.hasNext()){
Map.Entry<String, String> entry = it3.next();
System.out.println(entry.getKey()+":"+entry.getValue());
}
}
}
Map 遍历
最新推荐文章于 2025-05-09 18:52:02 发布
534

被折叠的 条评论
为什么被折叠?



