沒有說清楚,但是感覺你的意思應該是這樣的
public static void main(String[] args) throws Exception {
Map map1 = new HashMap();
map1.put("類型", "大");
map1.put("數量", "多");
map1.put("單價", 100);
map1.put("優惠", 0.12);
Map<String, Object> map2 = new HashMap<String, Object>();
map2.put("類型", "中");
map2.put("數量", "少");
map2.put("單價", 20);
map2.put("優惠", 0.42);
Map<String, List<Object>> maps = new HashMap<String, List<Object>>();
for(String key : map1.keySet()){
List<Object> list = maps.get(key);
if(list == null){
maps.put(key, list = new ArrayList<Object>());
}
list.add(map1.get(key));
}
for(String key : map2.keySet()){
List<Object> list = maps.get(key);
if(list == null){
maps.put(key, list = new ArrayList<Object>());
}
list.add(map2.get(key));
}
for(String key : maps.keySet()){
System.out.println(key + ":" + maps.get(key));
}
}
輸出為:
單價:[100, 20]
優惠:[0.12, 0.42]
類型:[大, 中]
數量:[多, 少]