---
title: "对集合中的对象做排序"
author: "kingdelee"
date: "2014-02-12T16:16:55Z"
tags: []
categories: ["编程语言"]
slug: "untitled"
draft: false
lastmod: "2014-02-12T23:34:23Z"
id: 2015723
url: "https://kingdelee.iteye.com/blog/2015723"
---

```java

final Map<Long, Integer> cardIdScountMap = this.buildCardIdScountMap(cardIdSet);

			Collections.sort(cardList, new Comparator<Card>() {
				@Override
				public int compare(Card o1, Card o2) {
					// 先比较scount，再比较是否有名片，最后再比较createTime
					if (cardIdScountMap.get(o1.getCardId()) > cardIdScountMap.get(o2.getCardId())) {
						return 1;
					}
					else if (!StringUtils.isEmpty(o1.getPic()) && StringUtils.isEmpty(o2.getPic())) {
						return 1;
					}
					else if (StringUtils.isEmpty(o1.getPic()) && !StringUtils.isEmpty(o2.getPic())) {
						return -1;
					}
					else if (o1.getCreateTime().after(o2.getCreateTime())) {
						return 1;
					}
					else {
						return -1;
					}
				}
			});

```