楼主要注意, map1里面的键是Integer类型,值是Map<String, String>,虽然值是两个String对象组合成的键值对,但仍然不能用{String,String}表示,而只能用{String=String}形式表示。
楼主想要实现的添加语句比较繁琐,慢慢的理清关系,一步一步的添加就可以了。因为map1有三个键,对应的有三个值,所以还要创建三个Map<String, String>对象,用来存放这三个键值对- Map<Integer, String> m1 = new HashMap<Integer, String>();
- Map<Integer, String> m2 = new HashMap<Integer, String>();
- Map<Integer, Map<String, String>> map1 = new HashMap<Integer, Map<String, String>>();
- Map<String, String> ms1 = new HashMap<String, String> ();
- Map<String, String> ms2 = new HashMap<String, String> ();
- Map<String, String> ms3 = new HashMap<String, String> ();
-
- m1.put(111, "1111");
- m1.put(222, "2222");
- m1.put(333, "3333");
- m2.put(111, "aaaa");
- m2.put(222, "bbbb");
- m2.put(333, "cccc");
- ms1.put(m1.get(111).toString(), m2.get(111));
- ms2.put(m1.get(222).toString(), m2.get(222));
- ms3.put(m1.get(333).toString(), m2.get(333));
- map1.put(111, ms1);
- map1.put(222, ms2);
- map1.put(333, ms3);
-
- //System.out.println(m1);
- System.out.println(map1);
复制代码 |