【问题标题】:League Table order points排行榜订单点
【发布时间】:2010-09-14 21:08:12
【问题描述】:

我需要让团队按点的顺序排序,从多到少,我必须编写一个新方法并且可以更改类标题。 我正在考虑将其用作我的方法,但它会使团队按最少到最多的顺序排列:S 所以我不知道如何解决它,我也不知道如果我需要对类标题进行哪些更改随便!

public void orderPoints()

{
 List<String> points = new ArrayList<String>();
 Collections.sort(points);
}

我知道我可以使用 Collections.max 和 min 但不确定如何过滤中的其余点

类的其余代码

公开课联赛 { /* 实例 变量 */
私人团队名称;
私有 int 点;

/** * League 类对象的构造函数。 */ 公开联赛(球队名称)
{ 超级();

  name = aName;

  points = 0;    }

/** * 返回接收者的名字 Team */ 公共团队 getName() { 返回这个名称; }

      /**
* Returns the receiver's points
*/    public int getPoints()    {
  return points;    }
     /**
* Sets the receiver's points
*/    public void setPoints(int aPoints)    {
  this.points = aPoints;    }

【问题讨论】:

    标签: java


    【解决方案1】:

    我不确定我是否理解您的要求,但如果您想反转列表的排序,您可以使用Collections.sort(points, Collections.reverseOrder());

    【讨论】:

    • 这就是我要 gedim 的方式,但它一直要求我声明我以前从未需要做的变量集合,这让我很困惑
    • public void points() { List points = new ArrayList(); Collections.sort(points, Collections.reverseOrder()); }
    猜你喜欢
    • 2020-05-05
    • 2015-06-22
    • 2021-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2010-12-31
    • 2021-03-09
    相关资源
    最近更新 更多