Vector v1 = new Vector();
A a = new A(); a.i=12; a.color=23;
v1.add(a);
A b = v1.get(0);
v1.remove(b); // 成功移除
Vector.remove(Object o) 內部調用 indexOf(o),而 indexOf 使用 == 比較引用地址(源碼中為 elementData[i] == o)。只要 b 與列表中元素指向同一對象,即可移除,不依賴 equals()。
ArrayList.remove(Object) 使用 equals() 比較,若未重寫則同樣比較引用。remove 行為取決於具體實現,但主流實現均先檢查引用相等(==),再調用 equals。equals() / hashCode()。Iterator.remove() 避免 ConcurrentModificationException。