I came across a piece of code that iterates over a map using its own set of records and only performs an action if entry! = Null
As far as I know, even if we do not enter anything on the map, it map.entrySetreturns an empty set, not null. Even if I put it {null,null}, then the record will be an [null=null]instance with these elements. But the instance will not be empty.
Map<String, String> map = new HashMap<String, String>();
map.put(null, null);
map.put(string1, string1);
for(Map.Entry<String, String> entry : map.entrySet()){
if(entry != null){
}
}
I have some basic questions:
- In which scenario will the HashMap write be NULL?
- Is the check even valid
I really believe if(entry != null)carefully and need to be removed. I just want to be sure.
source
share