在 Java IdentityHashMap 中获取特定键的值
要获取具体键的值,请使用 get() 方法。
设置你准备获取的键作为参数,并获取值。
假设你需要获取键 3 的值
get("3")以下是如何在 Java IdentityHashMap 中获取具体键的值:
示例
import java.util.*;
public class Demo {
public static void main(String[] args) {
Map<String, Integer> m = newIdentityHashMap<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
"+ m);
// Get the value of key 3
System.out.println("
The Value of key 3 in IdentityHashMap = " + m.get("3"));
}
}输出
输出如下
IdentityHashMap elements
{2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300}
The Value of key 3 in IdentityHashMap = 300
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP