Topic: 请叫一个关于ARRAYLIST的排序问题 |
Print this page |
1.请叫一个关于ARRAYLIST的排序问题 | Copy to clipboard |
Posted by: lajun Posted on: 2007-04-02 19:20 // 以下十个学生类和一个arraylist ,请教高手们怎么按学生分数"mark"对arraylist 进行排序!! class Student { String name; int mark=0; Student(String name ,int mark ){ this.name =name ; this.mark=mark; } string getN(){ return name ; } int getM(){ return makk; } } //建立一个arralist; Arraylist stus =new Arraylist ; for (int i=5;i<11; i++) stus.add(new Student("student"+i,i*10)) |
2.Re:请叫一个关于ARRAYLIST的排序问题 [Re: lajun] | Copy to clipboard |
Posted by: zcjl Posted on: 2007-04-03 09:02 java.util.Collections有个sort方法 sort(java.util.List list, java.util.Comparator c); 可参照下面的例子 http://www.exampledepot.com/egs/java.util/coll_SortList.html |
3.Re:请叫一个关于ARRAYLIST的排序问题 [Re: lajun] | Copy to clipboard |
Posted by: sanye303 Posted on: 2007-04-03 16:04 对姓名按音序排序: import java.util.*; import java.text.*; public class sortchinese { public static void main(String args[]) { Comparator cmp = (RuleBasedCollator)Collator.getInstance( java.util.Locale.CHINESE); String[] arr = {"张三", "里四", "王二", "王八"}; Arrays.sort(arr, cmp); for (int i = 0; i < arr.length; i++) System.out.println(arr[i].toString()); } } 你可以进行参照开发 |
Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1 客服电话 18559299278 客服信箱 714923@qq.com 客服QQ 714923 |