Question

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.

Était-ce utile?

La solution

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

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top