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

Java determines whether the specified object exists in the map

Release: 2020-01-14 14:14:27
Original
2581 people have browsed it

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));         
    }  
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template