小编Ran*_*las的帖子

排序 java.util.Deque

Deque<Card>我想使用Card类方法对集合的内容进行排序getRealValue()

\n\n
public class Card implements Comparable<Card> {\n  private final int value;\n  private final CardType cardType;\n\n  public Card(int value, CardType cardType) {\n    this.value = value;\n    this.cardType = cardType;\n  }\n\n  public int getRealValue() {\n    int realValue = this.value == 1 ? 52 : 0;\n    return realValue + this.value * 4 + this.cardType.ordinal();\n  }\n\n  public int compareTo(Card o) {\n    return this.getRealValue() - o.getRealValue();\n  }\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我的 CardType 枚举

\n\n
public enum CardType {\n    CLUB("\xe2\x99\xa3"),\n    SPADE("\xe2\x99\xa0"), \n    HEART("\xe2\x99\xa5"), …
Run Code Online (Sandbox Code Playgroud)

java collections arraydeque

2
推荐指数
1
解决办法
6647
查看次数

标签 统计

arraydeque ×1

collections ×1

java ×1