Java's HashSet is implemented using a HashMap, so it's also going to have redundancies. If you have done performance testing and found that to be a significant performance hit consider using a high-performance collections library such as GNU Trove (specifically TIntObjectHashMap).
How to use HashSet or a similar class with fast search and "get" method?
문제
JAVA Eclipse 3.8 "id" is the primary key for Product class. I need to store a list of "Product"s in a data structure which provides fast search like provided by HashSet and also i need to get/retrieve the searched object. Using a HashMap would result in redundant "id"s which is costly.
해결책
다른 팁
If your ID is unique (no two objects has the same ID), just define properly the equals() method of your to-be-stored objects and use HashSet instead.
제휴하지 않습니다 StackOverflow