Map of Maps data structure

后端 未结 3 2056
萌比男神i
萌比男神i 2020-12-11 16:53

The MultiValueMap class (Apache commons collections) makes it easy to work with a Map whose values are Collections. I\'m looking for a a class that makes it easy to work wit

3条回答
  •  旧时难觅i
    2020-12-11 17:12

    The regular Map collection works for this:

        Map> mapOfMaps = new LinkedHashMap>();
        Object newObject = new String("object as string");
        mapOfMaps.put(newObject, new LinkedHashMap());
        Map objectMap = mapOfMaps.get(newObject);
    

    In fact, if you're not worried about type safety, you can put whatever you want into the value section:

        Map mapOfWhatever = new LinkedHashMap();
        Object newObject = new String("object as string");
        mapOfWhatever.put(newObject, new LinkedHashMap());
        Map objectMap = (Map) mapOfWhatever.get(newObject);
    

提交回复
热议问题