Sort an ArrayList by primitive boolean type

前端 未结 8 866
北恋
北恋 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

    Another way to go is:

    Collections.sort(abc, new Comparator() {
            @Override
            public int compare(Abc abc1, Abc abc2) {
                return Boolean.compare(abc2.isClickable,abc1.isClickable);
            }
        });
    

提交回复
热议问题