This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sort list values

 
anvi kon
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

Can anyone help me to get the least values from the List?

Here is the code below.

List lst = getvalues(String s);

I have three values:lst.size() =3

150,25,250.

I need to sort it and get the lowest value 25.

How would I do that in java?

Thanks,





 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a requirement to sort the list? Or just to get the smallest value?

If all you want is the smallest value, there's no need to sort.

If you want to sort, then java.util.Collections has a sort() method that takes a List parameter, or, if you need to write your own, google for sorting algorithms or check your textbook.

Once you've clarified your actual requirements and taken your best shot, post again, showing your efforts and asking a more specific question than, "How do I sort?"

Good luck!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic