Java基础之常见容器

190 阅读1分钟

List

ArrayList

1、扩容

  • 默认初始容量为10,扩容为原容量的0.5倍加1

Vector

2、数据结构

数组

Map

HashMap

1、扩容

  • 默认初始容量为16,扩容为原容量的2倍,加载因子为0.75 2、数据结构 数据+链表 --->>> 数据+红黑树

Set

HashSet

1、扩容

  • 默认初始容量为16,扩容为原容量的2倍,加载因子为0.75

2、数据结构

底层数据结构是HashMap ,只是value为null而已

Queue

PriorityQueue

1、扩容

  • 默认初始容量为11,扩容为原容量的1.5倍

2、数据结构

底层结构:数组;逻辑结构:小根堆
// 传入Comparator接口 构造大根堆
PriorityQueue<Integer> pq = new PriorityQueue<Integer>(k, new Comparator<Integer>(){
    @Override
    public int compare(Integer o1, Integer o2){
        return 02.compareTo(o1);   //或者 o2 - o1
    }
})

参考文章