Home >Java >JavaBase >Java determines whether the specified object exists in the map

Java determines whether the specified object exists in the map

尚
Original
2020-01-14 14:14:272571browse

Java determines whether the specified object exists in the map

Map uses the containsValue method to determine whether it contains the specified value. (Recommended: java video tutorial)

Definition

containsValue(Object value) If this mapping maps one or more keys to the specified value, returns true

Example:

/** 
 *  
 * Map集合判断是否包含value
 * 
 */  
public class MapDemo   
{  
    public static void main(String[] args)  
    {  
        Map<String,Integer> m = new HashMap<String,Integer>();  
          
        m.put("zhangsan", 19);  
        m.put("lisi", 49);
        m.put("wangwu", 19);  
        m.put("lisi",20); 
        m.put("hanmeimei", null);         
        System.out.println(m);  
           
        System.out.println(m.containsValue(20));         
    }  
}

For more java knowledge, please pay attention to the java basic tutorial column on the PHP Chinese website.

The above is the detailed content of Java determines whether the specified object exists in the map. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn