192.168.1.57_20200907-湛良通

问题

已解决

    @Override
    public boolean containsAll(Collection<?> c) {

        if (c instanceof Bag) {
            Bag other = (Bag) c;
            Object[] newElements = other.elements;
            for (int i = 0; i < other.counter; i++) {
                X temp = (X) other.elements[i];
                if (!this.contains(temp)) {
                    return false;
                }
            }
        }
        return true;
    }
    @Override
    public boolean retainAll(Collection<?> c) {
        if (c instanceof Bag) {
            Bag other = (Bag) c;

            Object[] newElements = other.elements;
            for (int i = 0; i < other.counter; i++) {
                X temp = (X) other.elements[i];
                if (!this.contains(temp)) {
                    other.remove(i);
                }
            }
        }
        return false;
    }

吐槽

今天开始上集合了,老韩让我们自己试着编写以集合,实现集合中的方法。我觉得这样比直接给我们讲其中的方法好多了,这样我们可以更好的理解和记忆这些方法