Day18
HashMap底层
场景:
HashMap<Student, String> map = new HashMap<>(); map.put(null, "赏花");//null map.put(null, "抚琴");//赏花 map.put(new Student("宇", '男', 23, "2402", "001"), "踢足球");//null map.put(new Student("蒲", '男', 21, "2402", "002"), "看电影");//null map.put(new Student("小康", '男', 22, "2402", "003"), "看抖音");//null map.put(new Student("小康", '男', 22, "2402", "003"), "写代码");//看抖音
源码:
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>{ //默认初始化容量(必须是的2幂) - 16 static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; //最大容量 static final int MAXIMUM_CAPACITY = 1 << 30; //默认的负载因子 static final float DEFAULT_LOAD_FACTOR = 0.75f; //空内容的数组 static final Entry<?,?>[] EMPTY_TABLE = { }; //hash数组/hash表 - new Entry[16]; transient Entry<K,V>[] table = (Entry<K,V>[]) EMPTY_TABLE; //元素个数 transient int size;//0 //阈值 int threshold;//12 //负载因子 final float loadFactor;//0.75f