天天看點

學習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

繼續閱讀