Extracting a given number of the highest values in a List

Posted by James P. on Stack Overflow See other posts from Stack Overflow or by James P.
Published on 2010-04-12T20:31:19Z Indexed on 2010/04/12 20:32 UTC
Read the original article Hit count: 241

Filed under:
|
|
|

I'm seeking to display a fixed number of items on a web page according to their respective weight (represented by an Integer). The List where these items are found can be of virtually any size.

The first solution that comes to mind is to do a Collections.sort() and to get the items one by one by going through the List. Is there a more elegant solution though that could be used to prepare, say, the top eight items?

© Stack Overflow or respective owner

Related posts about java

Related posts about sort