相关疑难解决方法(0)

如何按某些属性对对象列表进行排序

我有简单的课程

public class ActiveAlarm {
    public long timeStarted;
    public long timeEnded;
    private String name = "";
    private String description = "";
    private String event;
    private boolean live = false;
}
Run Code Online (Sandbox Code Playgroud)

List<ActiveAlarm>con.如何按升序排序timeStarted,然后按timeEnded?有人可以帮忙吗?我知道在C++中使用泛型算法和重载运算符<,但我是Java的新手.

java sorting

134
推荐指数
7
解决办法
25万
查看次数

Java按字母顺序按自定义字段排序ArrayList

public class Product implements Serializable{

    private String id;
    private String name;
    private double price ;
    private int quantity;

    public Product(String id, String name, double price, int quantity) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.quantity = quantity;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    } …
Run Code Online (Sandbox Code Playgroud)

java sorting

8
推荐指数
2
解决办法
4万
查看次数

标签 统计

java ×2

sorting ×2