I want to remove keys from map in case if the value for the key is zero(0) i am able to achieve it using map.values().removeAll(Collections.singleton(0l));
.
It was working nice till i was using Map<String,Long>
but now we have changed the implementation to Map<String,AtomicLong>
now it dosen't remove the keys whose values are zero since i am using an Atomic variable as value.
Small code snippet on which i tried ::
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());
which outputs as {Ron=0, Fredrick=0, Gema=1, Andrew=1, David=0}
as you can see the keys which have values 0 are not being removed. Can anyone suggest a solution over this , it will be of great help.
Thanks.