vojelo
vojelo

Reputation: 35

HashSet vs LinkedHashSet and different results for the same task

Please, Can you explain, these different results. DartPad

Yet, Java has different point of view online runner

Upvotes: 0

Views: 249

Answers (1)

Harry Terkelsen
Harry Terkelsen

Reputation: 2714

In the case of HashSet and List, it looks like removeWhere is collecting the elements to be removed and then removing them all at the end. For LinkedHashSet, it is removing them as soon as they are found. removeWhere does not document it's implementation details, so I think it's unwise to give a test to removeWhere that depends on the contents of the List or Set.

Upvotes: 3

Related Questions