as set entries distinguished subset of properties (hashcode()
+ equals()
), there need operate on original object contained in set, not possible java.util.set
. alternative came is: map<t, t>
- not concise solution.
are there other alternatives in collections framework? requirements are: o(1) fetch time , no duplicates based on hashcode() + equals()
result.
if 1 more o(1) operation not problem, can simulate absenting method get(object)
pair of methods set.remove(object)
, set.add(object)
. otherwise, use map<t,t>
mentioned or simple wrapper class underlying map.
edit: reason why set
doesn't contain get(object)
don't need return object know. need check, if object contained in set or not.
Comments
Post a Comment