Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting 10 largest values from a Vector

Status
Not open for further replies.

kmcculler

Programmer
Jul 5, 2000
81
US
Currently I am loading 2 Vectors from an XML file read. The first Vector "values" has scores(stored as a BigDecimal), the second "labels" contains an appropriate label for that score (String).
Im loading them fine, but my next step is to find the 10 largest scores and print out only them and their label.
Does anyone know how I can find the 10 largest values and seperate them but keep them associated with the correct label?? Thanks in Advance
Kris McCuller
Programmer Portiva Corp.
kmcculler@portiva.com
 
Sort the Vector and take the top 10!!!

You could dump it to an array and sort the array or dump the vector elements to a sorted list (e.g. TreeSet).

Are all of the labels/scores unique? You could put them in a hashmap and then after sorting the scores, reacquaint the scores and labels.

There are many, many ways to do what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top