判断TreeMap中是否包含某个值,判断TreeMap包含,package cn.o
分享于 点击 12086 次 点评:253
判断TreeMap中是否包含某个值,判断TreeMap包含,package cn.o
package cn.outofmemory.snippets.core;import java.util.TreeMap;public class CheckValueTreeMap { public static void main(String[] args) { // Create a TreeMap and populate it with elements TreeMap treeMap = new TreeMap(); treeMap.put("key_1","element_1"); treeMap.put("key_2","element_2"); treeMap.put("key_3","element_3"); // boolean containsValue(Object key) returns true if the value is mapped to one or more keys otherwise false. boolean exists = treeMap.containsValue("element_2"); System.out.println("element_2 exists in TreeMap ? : " + exists); }}
输出:
element_2 exists in TreeMap ? : true
用户点评