This question already has answers here:
How to remove a key from HashMap while iterating over it? [duplicate]
                                
                                    (3个答案)
                                
                        
                        
                            iterating over and removing from a map [duplicate]
                                
                                    (12个答案)
                                
                        
                                5年前关闭。
            
                    
我有这样的功能,我应该在引用中找到所有键,这些键的值= null并删除它们。怎么做?

public static void garbageCollector(Map references){
            if (references.containsValue(null) ==true){
                ????
            }


提前致谢。

最佳答案

references.values().removeAll(Collections.singleton(null));


这应该只是为您完成工作:)

关于java - 我应该搜索HashMap中所有值= null的键并将其删除。我怎样才能做到这一点? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22663078/

10-17 01:15