![](/img/trans.png)
[英]How to use keySet() to retrieve a set of keys within a HashMap, loop over it and find its count for each key?
[英]How to use keySet().iterator() to find patterns in keys in a HashMap
我創建了一個HashMap和鍵集Iterartor,如下所示:
HashMap<Integer,String> map = new HashMap< Integer,String>();**
map.put(-1505711364, "4");
map.put(294357273, "15");
map.put(-1593134417, "28");
map.put(-1231165758, "45");
map.put(121046798, "58");
map.put(294357273, "71");
map.put(-1593134417, "82");
map.put(-1231165758, "95");
map.put(121046798, "108");
Iterator<Integer> keySetIterator = map.keySet().iterator();
我需要提取15,28,45
和71,82,95
因為它們具有相同的鍵模式。 同樣,我需要從大小2開始找到各種常見的模式。
如何使用keySetIterator做到這一點?
如果使用相同的鍵兩次運行map.put()
,它將覆蓋先前的條目。 這是因為基本假設是, Map
中的鍵是唯一的,因此每個鍵中只能存在一個。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.