天天看点

学习Key与Value的集合hashtable

你可以创建一个hashtable:

学习Key与Value的集合hashtable

你可以使用foreach方法,把hashtable的key与value循环写出来:

学习Key与Value的集合hashtable

在控制台屏幕输出:

学习Key与Value的集合hashtable

如果只需把key输出:

学习Key与Value的集合hashtable

如果只想把值循环输出:

学习Key与Value的集合hashtable

测试输出结果:

学习Key与Value的集合hashtable

往hashtable集合添加key与value:

学习Key与Value的集合hashtable

有添加就是移除:

学习Key与Value的集合hashtable

测试上面的添加Add和移除:

学习Key与Value的集合hashtable

key值为"A"已经被移除。

接下来,再练习2个方法,就是判断key或avlue是否已经存在集合:

学习Key与Value的集合hashtable

完整练习代码:

学习Key与Value的集合hashtable
学习Key与Value的集合hashtable

Source Code

继续阅读