Java IdentityHashMap containsValue()方法
使用该containsValue()方法检查值是否存在。首先,创建一个IdentityHashMap-
Map<String, Integer> m = new IdentityHashMap<String, Integer>();
添加一些元素-
m.put("1", 100);
m.put("2", 200);
m.put("3", 300);
m.put("4", 150);
m.put("5", 110);
m.put("6", 50);
m.put("7", 90);
m.put("8", 250);
m.put("9", 350);
m.put("10", 450);现在检查是否存在值-
m.containsValue(100))
以下是实现containsValue()方法的示例-
示例
import java.util.*;
public class Demo {
public static void main(String[] args) {
Map<String, Integer> m = new IdentityHashMap<String, Integer>();
m.put("1", 100);
m.put("2", 200);
m.put("3", 300);
m.put("4", 150);
m.put("5", 110);
m.put("6", 50);
m.put("7", 90);
m.put("8", 250);
m.put("9", 350);
m.put("10", 450);
System.out.println("IdentityHashMap elements\n"+ m);
System.out.println("Is value 100 in the Map? " + m.containsValue(100));
}
}输出结果
IdentityHashMap elements
{2 = 200, 4 = 150, 9 = 350, 7 = 90, 10 = 450, 6 = 50, 5 = 110, 8 = 250, 1 = 100, 3 = 300}
Is value 100 in the Map? true热门推荐
7 合字的祝福语简短
10 父亲祝福语大全简短语
11 元旦的祝福语简短 公司
12 大学报道祝福语简短
13 幼儿狗年祝福语大全简短
14 群里祝福语简短幽默
15 哥哥考大学祝福语简短
16 初八祝福语简短语
17 老师对学校祝福语简短
18 异性朋友简短生日祝福语