如何在给定变量的Java中对列表进行排序 [英] how to sort a list in java on the given variable
本文介绍了如何在给定变量的Java中对列表进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在Java中知道如何根据单个变量对列表对象进行排序.
例如:
假设我有
i want to know in java, how to sort the list object based on a single variable.
ex:
suppose i have
class student
{
string name;
float avg;
}
我创建一个列表并传递对象int列表,现在我想对avg进行详细排序.
and i create a list and pass the object int list , now I want to sort the details on avg.
推荐答案
请参阅此Java教程 [
See this Java Tutorial[^].
<Edit> Should have checked the linked after pasting it. It was missing the ''l'' from html.
对不起,以上链接不再存在.认为Oracle已对其进行了更新:
http://download.oracle.com/javase/tutorial/collections/algorithms/index.html
无论哪种方式,答案都位于Comparable或Comparator界面中.
干杯
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
这篇关于如何在给定变量的Java中对列表进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文