关键点 :将 Liste 内存储的对象实现 Comparable 类 , 重写它的 Comparto () 方法即可
Haricot:
Package CHC; classe publique Stuvo implémente comparable <Stuvo> {ID de chaîne privée; nom de chaîne privée; Âge entier privé; public Stuvo (nom de la chaîne, nom de chaîne, agent entier) {this.id = id; this.name = name; this.age = Âge;} public int compareto (stouvo stu) {return this.name.comPareto id;} public void setid (string id) {this.id = id;} public String getName () {return name;} public void setName (String name) {this.name = name;} public Integer getage () {return} Démo:
package chc; import java.util.arraylist; import java.util.collections; import java.util.iterator; import java.util.list; classe publique ArraylistsortDemo {public static void main (String [] args) {list <stuvo> stulist = new ArrayList <Stuvo> (); Stuvo Stu = new Stuvo ("1", "H 小明", 11); Stulist.add (Stu); Stu = new Stuvo ("2", "D 阿熊", 15); Stulist.Add (Stu); Stu = New Stuvo ("3", "A 张三", 10); Stulist.Add (Stu); Stu = New Stuvo ("4", "B 李四", 15); Stulist.add (Stu); Collection.Sort (Stulist); Iterator <Stuvo> it = Stulist.iterator (); while (it.hasnext ()) {System.out.println (it.next (). GetName ());}}}以上这篇 Java 按照 Liste 内存储的对象的某个字段进行排序的实例就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。