java中list排序

package com.renhenet.web.answer.view;

import java.util.Comparator;

import com.renhenet.vo.answer.AnswerFlowerVo;

/**
 * Title: FlowersComparator.java<br>
 * Description: <br>
 * Copyright (c) 人和网版权所有 2012	<br>
 * Create DateTime: 2012-6-8 下午01:55:53 <br>
 * @author  gj
 */
@SuppressWarnings("unchecked")
public class FlowersComparator implements Comparator {

	@Override
	public int compare(Object o1, Object o2) {
		AnswerFlowerVo c1 = (AnswerFlowerVo) o1;
		AnswerFlowerVo c2 = (AnswerFlowerVo) o2;
		if (c1.getFlowerCount() < c2.getFlowerCount()) {
			return 1;
		} else {
			if (c1.getFlowerCount() == c2.getFlowerCount()) {
				return 0;
			} else {
				return -1;
			}
		}
	}

}

以上代码是按照鲜花的数量由多到少进行排序。。。

Collections.sort(noneAnswerFlowerVoList, fcomparator);

 

你可能感兴趣的:(java中list排序)