List 类:ArrayList Vector LinkedList
这里只介绍特别之处:
ArrayList :public class ArrayList<E> extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
remove(object o):其中的参数如果是自己定义的类 必须覆写Object 的equal()方法和hashcode()方法:
//这个是remove(Object的源码)
public boolean remove(Object o) {
if (o == null) {
for (int index = 0; index < size; index++)
if (elementData[index] == null) {
fastRemove(index);
return true;
}
} else {
for (int index = 0; index < size; index++)
if (o.equals(elementData[index])) {
fastRemove(index);
return true;
}
}
return false;
}
需要用到equal()。
Vector:public class Vector<E>
extends AbstractList<E>
implements List<E>, RandomAccess, Cloneable, java.io.Serializable
Vector 的方法与ArrayList 的方法的功能都差不多
他是线程安全的操作类,实现了Cloneable ,Serializable接口。
他与ArrayList 相比性能较低(因为实现了线程安全)
LinkedList :public class LinkedList<E>
extends AbstractSequentialList<E>
implements List<E>, Deque<E>, Cloneable, java.io.Serializable
有队列的功能,也可把他看作双头队列,
Set :
hashset:
要想去重就必须实现 hashcode (),equals().
hashcode 是用来确定里面的node保存的位置,equals 来确定两个元素相不相等。
这里运用haspmap.put(,) 方法;
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}