实体类集合(List)根据实体类的一个或者多个属性对集合进行排序-Collections.sort

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u013165110/article/details/77884408
Collection.sort(userList, new Comparator<user>(){
	@Override
	public int compare(User u1, User u2){
		int ct=0;
		if(u2 == null){
			ct = -1;
		}
		if(ct == 0){
			String userId = u1.getUserId();
			String o_userId = u2.getUserId();
			if(userId == null){
				userId = "";
			}
			if(o_userId == null){
				o_userId = "";
			}

			ct = userId.compareTo(o_userId);
			if(ct == 0){
				String id = u1.getId();
				String o_id = u2.getId();
				if( id == null){
					id = "";
				}
				if(o_id == null){
					o_id = "";
				}
				ct = id.compareTo(o_id);
			}
		}
		return ct;
	
	}
});

猜你喜欢

转载自blog.csdn.net/u013165110/article/details/77884408