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
现在我想要把这些字的全部键位都输出出来,请问该怎么做呢???

解决方案 »

  1.   

    不知道LZ是不是要遍历所有的key,是的话看看下的代码 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);
    Set<String> keyset = map.keySet();
    Iterator<String> iterator = keyset.iterator();
    while(iterator.hasNext()){
    System.out.println(iterator.next());
    }
    }
      

  2.   

    我的意思是要求把codeA  codeB  codeC   codeD里的每个值所对应的键一起输出出来噢,是这个意思。
      

  3.   

    这么说吧,就是把codeA codeB codeC codeD的值所对应的键全部都放到一个集合里去,然后输出出来。
      

  4.   

    试试看  要什么  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(String key : map.keySet() ){
                System.out.println(key + "   " + map.get(key));
            }
        }
      

  5.   

     Set<String> keyset = map.keySet();
            Iterator<String> iterator = keyset.iterator();
            while(iterator.hasNext()){
                System.out.println(iterator.next());
            }
    这个不就是把所有的键都输出吗,输出a b c d不是这样吗?
      

  6.   

    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(String key : map.keySet() ){
                System.out.println(key + "   " + map.get(key));
            }
        }貌似这个不错。
      

  7.   

    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);
    }
    }
    }