📄 testhashtable.java
字号:
package apibook.c2.s1;import java.util.*;public class TestHashtable { public TestHashtable() { } public static void main(String[] args) { //创建一个Hashtable对象 Hashtable h1 = new Hashtable(); //设置Hashtable对象中的元素 h1.put("color","red"); //判断Hashtable对象中是否包含指定的元素 System.out.println(h1.containsKey("color")); System.out.println(h1.containsKey("blue")); System.out.println("---------------------------------"); h1.put("?","sport"); h1.put("cat","?"); h1.put("sweet","baby"); //获得Hashtable对象中的实体集 Set s1=h1.entrySet(); //对这个实体集进行迭代 for (Iterator it=s1.iterator();it.hasNext();) { Map.Entry e = (Map.Entry)it.next(); if (e.getValue().equals("?")) { e.setValue(e.getKey()); } else if(e.getKey().equals("?")){ it.remove(); } } System.out.println(h1); System.out.println("---------------------------------"); h1.put("fly","bird"); for (Iterator it=s1.iterator();it.hasNext();) { Map.Entry e = (Map.Entry)it.next(); System.out.print(e.getKey()+"="+e.getValue()+" "); } System.out.println("---------------------------------"); //获得Hashtable对象中的键的集合 Set s2 = h1.keySet(); System.out.println(new HashSet(s2)); System.out.println("---------------------------------"); //从Hashtable对象中删除指定的元素 s2.remove("fly"); System.out.println(h1); System.out.println("---------------------------------"); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -