-1

更新:-

问题陈述是-

我需要储存这些东西——

For ID corresponding to 1, I need to Store these things

 - Key CGUID(String CGUID) and its Value, Key SGUID(String SGUID) and its Value, Key PGUID(String PGUID) and its Value, Key UID(String UID) and its Value, Key ALOC(String ALOC) and its Value

For ID corresponding to 2, I need to Store these things

- Key CGUID(String CGUID) and its Value, Key SGUID(String SGUID) and its Value, Key PGUID(String PGUID) and its Value, Key UID(String UID) and its Value, Key ALOC(String ALOC) and its Value

For ID corresponding to 3, I need to Store these things

- Key CGUID(String CGUID) and its Value, Key SGUID(String SGUID) and its Value, Key PGUID(String PGUID) and its Value, Key UID(String UID) and its Value, Key ALOC(String ALOC) and its Value

因此,对于这个问题,我正在考虑制作这样的数据结构-

public static LinkedHashMap<String, Integer> GUID_VALUES = new LinkedHashMap<String, Integer>();

public static LinkedHashMap<Integer, LinkedHashMap<String, Integer>> GUID_ID_MAPPING = new LinkedHashMap<Integer, LinkedHashMap<String, Integer>>();

还有比这更好的方法吗?

4

3 回答 3

2

目前尚不完全清楚您最终要存储的内容。

如果您只想要地图地图:

LinkedHashMap<Integer, LinkedHashMap<String, Integer>>

但最后那些“等等等等”是什么?每个父 ID 是否有多个“子”ID?如果是这样,那么您可能想要某种树(可以通过地图实现,但对其进行抽象似乎是合理的。)

于 2012-05-28T21:53:36.913 回答
1

在 Java 中,您可以通过以下方式实现:

public class Data {
    public static LinkedHashMap<String, Integer> GUID_VALUES = new LinkedHashMap<String, Integer>();
    public static LinkedHashMap<Integer, Map<String, Integer>> GUID_ID_MAPPING = new LinkedHashMap<Integer, Map<String, Integer>>();

    static {
        Integer someNumber = 0; //or another value, its for initialize the key
        GUID_ID_MAPPING.put(someNumber,GUID_VALUES);
    }
}

不过,我不明白你为什么真的需要这个。我建议您发布您的功能要求并尝试选择更好的设计来解决问题。

于 2012-05-28T21:55:02.887 回答
0

您可能想要一个多键映射,就像 Apache Commons Collections 中可用的那样:

http://commons.apache.org/collections/api-release/org/apache/commons/collections/map/MultiKeyMap.html

于 2012-05-28T21:49:59.300 回答