好吧,你不介意我写我的“测试”项目;首先,我创建了实现 AbstractMap 的类。
public class TestClass <K, V> extends AbstractMap <K, V>
Run Code Online (Sandbox Code Playgroud)
TestClass 具有作为参数的私有 LinkedList(它是另一个实现 Map.Entry 的类:
private int size = 1000;
private LinkedList <InfoClass <K, V>> [] array = new LinkedList [size];
Run Code Online (Sandbox Code Playgroud)
之后,我创建了检查和替换重复项的方法:
public V put (K key, V value){ // Void doesn't work, therefore we need to return any value;
V temp = null;
boolean found = false;
int index = Math.abs(key.hashCode()) % size;
if (array[index] == null)
array[index] = new LinkedList <InfoClass <K, V>> (); // If …Run Code Online (Sandbox Code Playgroud) java ×1