JavaSE 计算2个List集合中的交集、差集、并集、去重并集


	JavaSE 计算2个List集合中的交集、差集、并集、去重并集
[编程语言教程]

VideoOrder.java

重写里面的equals和hashCode方法

class VideoOrder {
    private int price;
    private String title;

    public VideoOrder(String title, int price) {
        this.title = title;
        this.price = price;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        VideoOrder that = (VideoOrder) o;
        return price == that.price && Objects.equals(title, that.title);
    }

    @Override
    public int hashCode() {
        return Objects.hash(price, title);
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String toString() {
        return "VideoOrder{" + "price=" + price + ", title=‘" + title + ‘‘‘ + ‘}‘;
    }
}
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » JavaSE 计算2个List集合中的交集、差集、并集、去重并集