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!