Sort an ArrayList by primitive boolean type

前端 未结 8 886
北恋
北恋 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:31

    I want the items with true value to appear first. My solution would be:

    Collections.sort(m_mall, new Comparator(){
    
            @Override
            public int compare(Mall mall1, Mall mall2){
    
                boolean b1 = mall1.isClickable;
                boolean b2 = mall2.isClickable;
    
                return (b1 != b2) ? (b1) ? -1 : 1 : 0;
            }
        });
    

提交回复
热议问题