我想刪除的情況下,從地圖鍵,如果該鍵的值是零(0)我能夠使用map.values().removeAll(Collections.singleton(0l));
去實現它。
這是工作不錯,直到我用Map<String,Long>
,但現在我們已經改變了實施Map<String,AtomicLong>
現在這麼想的刪除其值是零,因爲我使用的是原子變量值的鍵。
一小段代碼上,我試着::刪除從地圖中原子的情況下,鍵值
Map<String, AtomicLong> atomicMap = new HashMap<String,AtomicLong>();
atomicMap.put("Ron", new AtomicLong(0l));
atomicMap.put("David", new AtomicLong(0l));
atomicMap.put("Fredrick", new AtomicLong(0l));
atomicMap.put("Gema", new AtomicLong(1l));
atomicMap.put("Andrew", new AtomicLong(1l));
atomicMap.values().removeAll(Collections.singleton(new AtomicLong(0l)));
System.out.println(atomicMap.toString());
其輸出爲{Ron=0, Fredrick=0, Gema=1, Andrew=1, David=0}
你可以看到具有值0鍵沒有被刪除。任何人都可以提出解決方案,這將是非常有幫助的。
謝謝。