【发布时间】:2014-12-28 06:26:13
【问题描述】:
我正在尝试存储数据并根据他们的 id 取回数据。数据类型是。
int Q_ID -------> Id of the Question
int Type_Question ----> Which type is the Question
ArrayList<String> Options ----> The options are multiple and are determined at run based on users selection of the options
现在我想存储数据。例如以这种方式。
Q_ID=0
Type_question=1
Options.add("handpump");
Options.add("Well");
Q_ID=1
Type_question=1
Options.add("random");
Options.add("answer");
有没有办法可以存储它们,以便当我输入 Q_ID = 0 和 Type_Question=1;它只返回手动泵和井,如果输入 Q_ID = 1 和 Type_question=1,它只返回随机和答案。 这可能太明显了,但我什么都想不出来。有什么想法吗?
【问题讨论】:
-
不同的数据结构适用于不同的事物。为了高效查找,您需要一个“字典”数据结构。 Java 中一个优秀的候选者是Map,例如“HashMap”。
-
非常感谢我已经解决的建议:)