1.LinkList
//链表节点模型
private static class Node<E> {
E item;
Node<E> next;
Node<E> prev;
Node(Node<E> prev, E element, Node<E> next) {
this.item = element;
this.next = next;
this.prev = prev;
}
}
2.ArrayList
//初始化大小为10;
int DEFAULT_CAPACITY = 10;
//存储结构为数组
private transient Object[] elementData;
//扩容方式,扩大一倍,复制数组
private void grow(int minCapacity) {
int oldCapacity = elementData.length;
int newCapacity = oldCapacity + (oldCapacity >> 1);
elementData = Arrays.copyOf(elementData, newCapacity);
}
3.HashSet
//底层为hashMap,默认为16;
public HashSet(Collection<? extends E> c) {
map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16));
addAll(c);
}
//hashSet对象为key,value为固定的object对象的hashMap,具体看hashMap方法
public boolean add(E e) {
return map.put(e, PRESENT)==null;
}
网友评论