troubleshooting Question

Can a HashSet be ordered on a non-key field?

Avatar of BrianMc1958
BrianMc1958 asked on
Java
6 Comments3 Solutions590 ViewsLast Modified:
Dear Experts,

I have a HashSet containing "Customer" beans.  Each bean contains a CustName and a CustScore.  I override "equals" and "hash" using CustName only.  CustScore is just an ordinary field in the bean.

However, I now need to determine which customers were in the top 10% of CustScores.  I know I can do this by iterating the set, and then building and sorting internal arrays.  But I'm wondering if there is some way to directly tell the HashSet, "Give me all the customer beans in CustScore order"?

Thanks,
BrianMc1958
ASKER CERTIFIED SOLUTION
Giant2

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros