HashSet.remove() and Iterator.remove() not working

前端 未结 10 1526
借酒劲吻你
借酒劲吻你 2020-12-13 00:32

I\'m having problems with Iterator.remove() called on a HashSet.

I\'ve a Set of time stamped objects. Before adding a new item to the Set, I loop through the set, i

10条回答
  •  情书的邮戳
    2020-12-13 01:10

    Have you tried something like

    boolean removed = allResults.remove(oldData)
    if (!removed) // COMPLAIN BITTERLY!
    

    In other words, remove the object from the Set and break the loop. That won't cause the Iterator to complain. I don't think this is a long term solution but would probably give you some information about the hashCode, equals and equalsData methods

提交回复
热议问题