Java Comparator 对象比较器

package cn.edu.xmu.ru.utils;

import java.util.Comparator;

import cn.edu.xmu.ru.domain.Slashdot;

public class RUComparator implements Comparator {
	@Override
	public int compare(Object o1, Object o2) {
		Slashdot one = (Slashdot)o1;
		Slashdot theother = (Slashdot)o2;
		if(one.getScore() <= theother.getScore()){
			return -1;
		}else if(one.getScore() > theother.getScore()){
			return 1;
		}
		return 0;
	}
}

Collections.sort(lst, new RUComparator());
 

猜你喜欢

转载自irwenqiang.iteye.com/blog/1409696