list的sort排序方法


List<String> words , java 1.8 及以上用lambda表达式

1.

Collections.sort(words,new Comparator<String>(){

   public int compare(){

    return Integer.compare(s1.length(),s2.length)

  }

})

 

2.collections.sort(words,

  (S1,S2) -> Integer.compare(s1.length,s2.length)

)

 

3.Collections.sort(woeds,compring(String::length));

 

4.words.sort(compring(String::length))


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM