赞
踩
- package com.jianshun;
-
- //用于SxtHashMap中
- public class Node2 {
-
- int hash;
- Object key;
- Object value;
- Node2 next;
-
- }
- package com.jianshun;
- /**
- * 自定义一个HashMap
- * 重写toString方法,方便我们查看HashMap的键值对信息
- * @author Administrator
- *
- */
- public class SxtHashMap02 {
-
- Node2[] table; //位桶数组 bucket array
- int size; //存放键值对的个数
-
- public SxtHashMap02(){
- table = new Node2[16]; // 长度一般指定为2的整数幂
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
- for(int i=0;i<table.length;i++){
- Node2 temp = table[i];
-
- while(temp!=null){
- sb.append(temp.key+":"+temp.value+",");
- temp = temp.next;
- }
-
- }
- sb.setCharAt(sb.length()-1,'}');
- return sb.toString();
- }
-
- //向HashMap中存储数据
- public void put(Object key,Object value){
- //定义了新的节点对象
- Node2 newNode = new Node2();
- newNode.hash= myHash(key.has
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。