在 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