我想計算我的數組中的itemids數量,我可以得到一個關於如何將其添加到我的代碼中的示例。下面的代碼;計算我的數組列表中的項目數
if (value != null && !value.isEmpty()) {
Set set = value.keySet();
Object[] key = set.toArray();
Arrays.sort(key);
for (int i = 0; i < key.length; i++) {
ArrayList list = (ArrayList) value.get((String) key[i]);
if (list != null && !list.isEmpty()) {
Iterator iter = list.iterator();
double itemValue = 0;
String itemId = "";
while (iter.hasNext()) {
Propertyunbuf p = (Propertyunbuf) iter.next();
if (p != null) {
itemValue = itemValue + p.getItemValue().doubleValue();
itemId = p.getItemId();
}
buf2.append(NL);
buf2.append(" " + itemId);
}
double amount = itemValue;
totalAmount += amount;
}
}
}
我不認爲這個問題與示例代碼很好地相互配合。你在尋找'獨特'itemIds或相似的數量嗎? – 2010-09-13 20:38:12