Example | |
|
Solution | |
In the given example, the List "contains" method will perform a linear search, which can be expensive if the list is large. If changed to a set there will be no need to call contains since Set guarantees uniqueness. Suggested change:
| |
If order of insertion is important use LinkHashSet instead of HashSet. Suggested change:
|