package com.haixintext.java; //哈希节点 public class HashMapNode { int hash; Object key; Object value; HashMapNode next; }
package com.haixintext.java; //hashmap方法 public class HashMap { HashMapNode[] table; //位桶数组 int size; //存放键值对个数 public HashMap() { table = new HashMapNode[16]; //长度一般定义成2的整数幂 System.out.println("构造函数启动啦"); } public void put(Object key,Object value){ HashMapNode newHashMapNode = new HashMapNode(); newHashMapNode.hash = myHash(key.hashCode(),table.length); newHashMapNode.key = key; newHashMapNode.value = value; newHashMapNode.next = null; Boolean keyRepeat = false; HashMapNode temp = table[newHashMapNode.hash]; HashMapNode lasttemp = null; if(temp==null){ table[newHashMapNode.hash]=newHashMapNode; size++; }else {