package com.xiaoer.javaSEstudy; import java.util.HashMap; import java.util.Map; import org.junit.Test; public class TestHashMapIterator { @Test public void testEntrySet(){ Map<String, String> map = new HashMap<String, String>(); map.put("1", "王宁"); map.put("2", "王寒"); map.put("3", "王慧"); for(Map.Entry<String, String> entry:map.entrySet()){ System.out.println("key:"+entry.getKey()+",value:"+entry.getValue()); } } @Test public void testKeySet(){ Map<String, String> map = new HashMap<String, String>(); map.put("1", "王宁"); map.put("2", "王寒"); map.put("3", "王慧"); for(String key:map.keySet()){ System.out.println("key:"+key+",value:"+map.get(key)); } } }
时间: 2024-09-29 20:24:40