Sort an ArrayList by primitive boolean type

前端 未结 8 837
北恋
北恋 2020-12-09 16:08

I want to sort my ArrayList using a boolean type. Basically i want to show entries with true first. Here is my code below:

Abc.java

相关标签:
8条回答
  • 2020-12-09 16:48

    It is also possible that way.

    myList.sort((a, b) -> Boolean.compare(a.isSn_Principal(), b.isSn_Principal()));
    
    0 讨论(0)
  • 2020-12-09 16:49

    Java 8:

     Collections.sort(abc, (abc1, abc2) ->
                      Boolean.compare(abc2.isClickable(), abc1.isClickable()));
    
    0 讨论(0)
提交回复
热议问题