main.java
来自「电子工业出版社出版的《java2应用开发指南》配套光盘源代码」· Java 代码 · 共 45 行
JAVA
45 行
import java.util.*;
class Main
{
public static void main(String[] args)
{
Hashtable h = new Hashtable();
h.put("dog", "spot");
h.put("cat", "luck");
h.put("cow", "spot");
h.put("yak", "spot");
Collection col = h.values();
// [luck, spot, spot, spot, ]
printCol( col );
// true
System.out.println( col.contains("spot") );
// remove() removes one entry from the h.
col.remove("spot");
// {cat=luck, cow=spot, yak=spot}
System.out.println( h );
// removeAll() removes all entries with the value "spot".
col.removeAll(Collections.singleton("spot"));
// {cat=luck}
System.out.println( h );
// Add to the h and check the collection
h.put("dog", "spot");
// [luck, spot, ]
printCol( col );
// You can't add to the collection.
//col.add("bess");
// UnsupportedOperationException
}
static void printCol(Collection c)
{
System.out.print("[");
for (Iterator it=c.iterator(); it.hasNext(); )
{
System.out.print(it.next()+", ");
}
System.out.println("]");
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?