日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

List排序的问题

發(fā)布時間:2025/7/14 编程问答 17 豆豆
生活随笔 收集整理的這篇文章主要介紹了 List排序的问题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

1.對List進(jìn)行排序可以通過這種方式,實現(xiàn)(implements) Comparable<T>接口
@Overridepublic int compareTo( T o){if (null == o){return -1;}RunningInstancesItemType instance0 = this.instanceInfo;RunningInstancesItemType instance1 = o.getInstanceInfo();if (null == instance0 || null == instance1){return -1;}else{// 按運行時間排序String launchTime0 = this.getInstanceInfo().getLaunchTime();String launchTime1 = o.getInstanceInfo().getLaunchTime();if (!launchTime0.equals(launchTime1)){return launchTime1.compareTo(launchTime0);}else{// 如果運行時間相同,則按Id排序String instanceId0 = this.getInstanceInfo().getInstanceId();String instanceId1 = o.getInstanceInfo().getInstanceId();return instanceId0.compareTo(instanceId1);}}}@Overridepublic boolean equals(Object obj){boolean equals;if (null == obj){equals = false;}else if (this == obj){equals = true;}else if (this.getClass() != obj.getClass()){equals = false;}else{InstanceBean o = (InstanceBean)obj;RunningInstancesItemType instance1 = this.instanceInfo;RunningInstancesItemType instance2 = o.getInstanceInfo();if (null == instance1 || null == instance2){equals = false;}else{if (null == instance1.getLaunchTime()){equals = false;}else{equals = instance1.getLaunchTime().equals(instance2.getLaunchTime());}}}return equals;}@Overridepublic int hashCode() {final int prime = 31;int result = 1;result = prime * result+ ((null == this.getInstanceInfo() || null == this.getInstanceInfo().getLaunchTime()) ?0 : this.getInstanceInfo().getLaunchTime().hashCode());return result;}
2.也可以使用TreesSet實現(xiàn)
SortedSet<T> sortedSet = new TreeSet<T>(); List<T> instanceList; sortedSet.add(***);//此處*為T的實例化 instanceList = new ArrayList<T>(sortedSet);

轉(zhuǎn)載于:https://my.oschina.net/lgscofield/blog/471202

總結(jié)

以上是生活随笔為你收集整理的List排序的问题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。