完全不是当年考研中数据结构里的hash表,当时书中只说如何存放,冲突怎么处理,一直以为存的就是一个元素,后来一想get时输入什么呢,一看jdk源码才知道,原来存的是键值对,是两个元素,与HashMap相似!!看来不能读死书啊,要活学活用!
/**
* Title: HashTableCuston
* Description:
*
* @date 2017/12/24 18:51
*/
public class HashTableCuston<K, V> {
private Entry<?, ?>[] table;
private int capacity;
public HashTableCuston() {//默认构造函数,暂时未加入装载因子,未完待续
this(11);
}
public HashTableCuston(int capacity) {
if(capacity < 0){
throw new IllegalArgumentException("Illegal capacity :"+capacity);
}
this.capacity = capacity;
table = new Entry<?, ?>[capacity];
}
private static class Entry<K, V> {
int hash;
K key;
V value;
Entry&l