Click here to Skip to main content
15,896,727 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,
i want to know in java, how to sort the list object based on a single variable.
ex:
suppose i have
Java
class student
{
    string name;
    float avg;
}

and i create a list and pass the object int list , now I want to sort the details on avg.
Posted
Updated 4-Oct-11 4:16am
v3
Comments
TorstenH. 4-Oct-11 10:17am    
I added the homework tag and formatted the code.

What do you've got? and what are you passing where?
Please post your code snippet as we want to make sure you do your homework yourself.

See this Java Tutorial[^].

<Edit> Should have checked the linked after pasting it. It was missing the 'l' from html.
 
Share this answer
 
v2
sorry, the above link does not exist any more. Think Oracle have updated it :

http://download.oracle.com/javase/tutorial/collections/algorithms/index.html

Either way the answer lies in the Comparable or Comparator interface.

Cheers
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900