Runtime:
package com.codeurjava.hashtable;
导入 java.util.*;
public class hashtable_put {
public static void main(String args[]) {
// 创建一个 hashtable
Hashtable ht = new Hashtable();
// insert peers
ht.put(1, A”);
ht.put(2, B”);
ht.put(3, C”);
System.out.println(修改前的哈希表:”+ht);
// 修改 2
String val_ret=(String)ht.put(2,BB”);
System.out.println(替换值:”+val_ret);
System.out.println(修改后的哈希表:”+ht);
}
}
初始哈希表值:{3=C, 2=B, 1=A}
替换值:B
新建哈希表:{3=C, 2=BB, 1=A}
ht.replace(2,B”,BB”);Ressources:
Please disable your ad blocker and refresh the window to use this website.