java開發中list自身排序

 

 java 實現list中對象自身屬性的排序java

Collections.sort(list, new Comparator<myPlayFile>() {  對象

            public int compare(myPlayFile arg0, myPlayFile arg1) {  
               int flag = arg0.lastModified().compareTo(arg1.lastModified());
   return flag;
            }  
        });   排序

 

方法中,myPlayFile爲list集合中對象,對象中有一個屬性lastModified,比較的就是這個屬性開發

(原理根據返回值:1 :0:-1)三個值排序get

倒敘的話:只要io

flag=-flag就好了!ast

後續有不少開發填坑的文章發佈,若是對你有幫助,請支持和加關注一下原理

http://e22a.com/h.05ApkG?cv=AAKHZXVo&sm=339944方法

https://shop119727980.taobao.com/?spm=0.0.0.0 sort

相關文章
相關標籤/搜索