문제

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.

도움이 되었습니까?

해결책

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).

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top