如果應用程序是單線程的,請使用HashMap
。您可以「嵌套」HashMap
,例如HashMap<String, HashMap<Integer, HashMap<Integer, HashMap<String, Item>>>>
。請參閱this question以瞭解如何迭代HashMap
。
下面是僅使用兩個嵌套給你的想法一些示例代碼:
HashMap<String, HashMap<Integer, HashMap<Integer, HashMap<String, String>>>> map1 = new HashMap<String, HashMap<Integer, HashMap<Integer, HashMap<String, String>>>>();
map1.put("Computers", new HashMap<Integer, HashMap<Integer, HashMap<String, String>>>());
map1.get("Computers").put(2011, new HashMap<Integer, HashMap<String, String>>());
map1.get("Computers").get(2011).put(2, new HashMap<String, String>());
不相關:它應該是「學期」,而不是「Semister」 – Nishant 2011-01-09 16:47:38
@Nishant是啊,正確...... :) – sasidhar 2011-01-09 18:01:06
這是一個JavaScript的GUI,如extJS或GWT?你的數據庫泄露給客戶一個問題?數據庫很慢?你在使用ORM嗎?你打算使用一個嗎?是否有任何複雜的業務邏輯需要在Java級別上完成?驗證呢?我會試圖回答*「無」*作爲最好的數據結構。數據庫調用這些信息的速度似乎不太可能,如果數據*「極不可能改變」*,那麼像Hibernate這樣的ORM將非常輕鬆地爲您緩存所有這些信息。要麼你有一個數據庫,但用Java複製它並不聰明。 – SyntaxT3rr0r 2011-01-09 18:37:42