嵌套哈希
某个公司分为多个部门,各部门的名称不同,而且公司不设立统一工号,而是每个部门内部自己指定工号,各个部门之间的工号有可能相同。编写程序,用户输入部门名称和工号,检索出对应的人和人名。我晕啊,到底什么是哈希呀?

解决方案 »

  1.   

    hashmap<hashmap<String,String>>?
      

  2.   

    hashmap <String,hashmap <String,String> > ?
      

  3.   

    就像是二维数组。
    Hashtable<String, Hashtable<String, String>>
    ==>
    outerKey1,{{"key1","value1"},{"key2","value2"}}
    outerKey2,{{"key1","value1"},{"key2","value2"}}
    outerKey3,{{"key1","value1"},{"key2","value2"}}
      

  4.   

    //部门Hash
    Hashtable BuMen=new Hashtable ();
    //人员Hash
    Hashtable man1=new Hashtable ();
    man1.put("101","赵本山");
    man1.put("102","王菲"); 
    Hashtable man2=new Hashtable ();
    man2.put("101","卢比");
    man2.put("102","钢弹");
    //将人员Hash 当作部门Hash的value
    BuMen.put("bumen1",man1);
    BuMen.put("bumen2",man2);
     
    //查看部门2 的 编号102的人
    System.out.print(((Hashtable) BuMen.get("bumen2")).get("102"));