标签:string 编号 遍历 highlight imp int 使用 key ash
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class ss { public static void main(String[] args) { Map<String,String> map=new HashMap(); map.put("亚亚","Q妹"); map.put("菲菲","Q妹"); map.put("欧欧","Q仔"); map.put("美美","Q妹"); Set<String> keyset = map.keySet(); Iterator<String> iter = keyset.iterator(); while (iter.hasNext()){ String key = iter.next(); String value = map.get(key); System.out.println(key+"\t"+value); } } }
在上机3的基础上,为企鹅添加一个编号,并作为键存储多个企鹅信息到应用泛型的HashMap集合 使用Iterator、foreach语句进行遍历
import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Set; public class ss { public static void main(String[] args) { Map<String,String> map=new HashMap(); map.put("亚亚","Q妹"); map.put("菲菲","Q妹"); map.put("欧欧","Q仔"); map.put("美美","Q妹"); Set<String> keyset = map.keySet(); Iterator<String> iter = keyset.iterator(); while (iter.hasNext()){ String key = iter.next(); String value = map.get(key); System.out.println(key+"\t"+value); } System.out.println("使用foreach遍历"); for (String key : keyset) { String value = map.get(key); System.out.println(key+"\t"+value); } } }
标签:string 编号 遍历 highlight imp int 使用 key ash
原文地址:https://www.cnblogs.com/Libreation/p/13110961.html