【lambda表达式对LIST对象多个字段进行排序】

lambda表达式对LIST对象多个字段进行排序


对象InfoStat实体类
public class InfoStat {

	public InfoStat() {
	}
	
    private String strColId;					
	private String strWebSiteId;					
    private String strUnitId;					
    private Integer intUnitType;				
    private String strUserId;					
    private String strUserName;					
    private String strSource;					
    private Integer intAmount;					
    private Integer intCount;					
    private Integer intSort;					
    private Integer intScore;					

	private String strWebSiteName;				
	private String strColName;					
	private String strUnitName;					
	private Integer intPassCount;			
	private String intNoPassCount;				
	private String intReturnCount;				
	private String intReturnNoCount;				

	
	public Integer getIntScore() {
		return intScore;
	}

	public void setIntScore(Integer intScore) {
		this.intScore = intScore;
	}

	public String getStrWebSiteId() {
		return strWebSiteId;
	}

	public void setStrWebSiteId(String strWebSiteId) {
		this.strWebSiteId = strWebSiteId;
	}
	public Integer getIntUnitType() {
		return intUnitType;
	}

	public void setIntUnitType(Integer intUnitType) {
		this.intUnitType = intUnitType;
	}

	public String getStrColId() {
		return strColId;
	}

	public void setStrColId(String strColId) {
		this.strColId = strColId;
	}

	public String getStrUnitId() {
		return strUnitId;
	}

	public void setStrUnitId(String strUnitId) {
		this.strUnitId = strUnitId;
	}

	public String getStrUserId() {
		return strUserId;
	}

	public void setStrUserId(String strUserId) {
		this.strUserId = strUserId;
	}

	public String getStrUserName() {
		return strUserName;
	}

	public void setStrUserName(String strUserName) {
		this.strUserName = strUserName;
	}

	public String getStrSource() {
		return strSource;
	}

	public void setStrSource(String strSource) {
		this.strSource = strSource;
	}

	public Integer getIntAmount() {
		return intAmount;
	}

	public void setIntAmount(Integer intAmount) {
		this.intAmount = intAmount;
	}

	public Integer getIntCount() {
		return intCount;
	}

	public void setIntCount(Integer intCount) {
		this.intCount = intCount;
	}

	public Integer getIntSort() {
		return intSort;
	}

	public void setIntSort(Integer intSort) {
		this.intSort = intSort;
	}

public String getStrColName() {
	return strColName;
}

public void setStrColName(String strColName) {
	this.strColName = strColName;
}

public Integer getIntPassCount() {
	return intPassCount;
}

public void setIntPassCount(Integer intPassCount) {
	this.intPassCount = intPassCount;
}

public String getIntNoPassCount() {
	return intNoPassCount;
}

public void setIntNoPassCount(String intNoPassCount) {
	this.intNoPassCount = intNoPassCount;
}

public String getIntReturnCount() {
	return intReturnCount;
}

public void setIntReturnCount(String intReturnCount) {
	this.intReturnCount = intReturnCount;
}

public String getIntReturnNoCount() {
	return intReturnNoCount;
}

public void setIntReturnNoCount(String intReturnNoCount) {
	this.intReturnNoCount = intReturnNoCount;
}

public String getStrWebSiteName() {
	return strWebSiteName;
}

public void setStrWebSiteName(String strWebSiteName) {
	this.strWebSiteName = strWebSiteName;
}

public String getStrUnitName() {
	return strUnitName;
}

public void setStrUnitName(String strUnitName) {
	this.strUnitName = strUnitName;
}

}
排序操作:
List iss = new ArrayList<>();
一系列操作,最终iss里是查出来的数据集合
按照intPassCount字段降序
Comparator intPassCount=Comparator.comparing(InfoStat::getIntPassCount).reversed();
(升序Comparator intPassCount=Comparator.comparing(InfoStat::getIntPassCount);)
按照intCount字段降序
Comparator intCount=Comparator.comparing(InfoStat::getIntCount).reversed();
联合排序(如果条件更多继续按照上面操作,下面在后面接着.thenComparing(xxx))
Comparator finalCount=intPassCount.thenComparing(intCount);//联合排序
iss=iss.stream().sorted(finalCount).collect(Collectors.toList());//最后获取最终排序集合

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

whq1576049813

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值