提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
从哈希表获取键的集合视图
/*来自 时代Java公众号*/ import java.util.Enumeration; import java.util.Iterator; import java.util.Hashtable; import java.util.Set; public class Main { public static void main(String[] args) { Hashtable ht = new Hashtable(); ht.put("1","One"); ht.put("2","Two"); ht.put("3","Three"); Set st = ht.keySet(); System.out.println("Set created from Hashtable Keys contains :"); Iterator itr = st.iterator(); while(itr.hasNext()) System.out.println(itr.next()); st.remove("2");//nowjava - 时代Java 提供 System.out.println(