我有頁獲得ArrayList <文檔>其中每個文檔都有一個稱爲類型的屬性。Java將ArrayList映射到HashMap
我不知道唯一類型或文檔的數量。
我想將這個ArrayList排序成一個HashMap <類型,文檔[] >,但我有一些麻煩得到我的頭。
一些僞代碼願像
for (int i = 0; i < documents.size(); i++)
{
if there is an array for documents[i].type
add to this array
else create a new array for this type
add document[i].type and the array of documents with matching type to the hashmap
}
我知道這是錯誤的做法,明確將無法正常工作。我願意接受任何建議。
謝謝
+1用於添加有用的評論 – Ibrahim 2010-09-28 00:16:29