日期:2014-05-19  浏览次数:20746 次

关于Map取值对应到的键问题
String[] codeA="黯 鏖 鳌 鏊 霭 螯 聱 鹌 锿 锕";
String[] codeB="鬓 鞴 魃 髌 髀 鳔 鳊 鲅 鐾 踣";
String[] codeC="黪 黜 魑 鲳 雠 龊 龀 躔 蹴 蹰";
String[] codeD="黩 黛 髑 骶 鞑 靼 鲽 鲷 貂 踱";

Map<String, String[]> map = new HashMap<String, String[]>();
map.put("a", codeA);
map.put("b", codeB);
map.put("c", codeC);
map.put("d", codeD);
因为我把codeA,B,C,D都存放到map里去了,也就意味着codeA或者B他们缩对应的字的键为a,b
现在我想要把这些字的全部键位都输出出来,请问该怎么做呢???

------解决方案--------------------
public static void main(String[] args) {
String[] codeA={"黯","鏖","鳌 ","鏊","霭","螯","聱","鹌","锿","锕"};
String[] codeB={"鬓","鞴","魃","髌","髀","鳔","鳊","鲅","鐾 ","踣"};
String[] codeC={"黪","黜","魑","鲳","雠 ","龊"," 龀"," 躔"," 蹴"," 蹰"};
String[] codeD={"黩","黛","髑 ","骶 ","鞑 ","靼"," 鲽 ","鲷 ","貂 ","踱"};

Map<String, String[]> map = new HashMap<String, String[]>();
map.put("a", codeA);
map.put("b", codeB);
map.put("c", codeC);
map.put("d", codeD);
for (Entry<String, String[]> e : map.entrySet()) {
for (String v : e.getValue()) {
System.out.println(e.getKey()+":"+v);
}
}
}