且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从arraylist和hashmap中删除重复项

更新时间:2022-12-12 19:18:38

您正在将Map的条目添加到原始List中.您应该先清除它们:

You are adding the entries of the Map to the original Lists. You should clear them first:

nameArray.clear();
priceArray.clear();
for (Map.Entry<String, BigDecimal> entry : totals.entrySet()) {
    nameArray.add(entry.getKey());
    priceArray.add(entry.getValue());
}

或者,如果您不想覆盖原始的List,则应创建新的ArrayList.

Or, if you don't want to overwrite the original Lists, you should create new ArrayLists.