0
嗯,我有一個類命名的數據:基於身份和頭銜的java機器人分揀兩次
public class Data implements Comparable<Data>{
public String title;
public String description;
public String inststatus;
public int imageId;
Data(String title, String description, int imageId,String inststatus) {
this.title = title;
this.description = description;
this.imageId = imageId;
this.inststatus = inststatus;
}
@Override
public int compareTo(Data another) {
if(this.inststatus.equals("Present")){
return this.title.compareTo(another.title);
}else // Not Present
return this.inststatus.compareTo(another.inststatus); // ascending
}
}
現在,如果你看到基於按升序排列標題我已經比較它的類,但我想要做的排序兩個規則
inststatus有2個值: - 「存在」和「不存在」 1. inststatus =「存在」應該來在上面,在此之後,所有的人都應該以升序排序 2. inststatus =「不在場」應該出現在底部,之後,他們都應該按升序排列
現在讓我們來看一個例子,我們有價值觀
title = abc ,status = present
title = bcd , status not present
title = xyz ,status = present
title = aac ,status not present
現在上面2條規則後,它應該是列表排序
1. abc // present and also ascending
2. xyz
3. aac // now left ones not present and also ascending
4. bcd
完美標記爲答案,按預期工作 – AndroidBeginnerJhon