在 Java IdentityHashMap 中获取特定键的值

java 8object oriented programmingprogramming

要获取特定键的值,请使用 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 元素
"+ m);       // 获取键 3 的值       System.out.println("
IdentityHashMap 中键 3 的值 = " + m.get("3"));    } }

输出

输出如下

IdentityHashMap 元素
{2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300}
IdentityHashMap 中键 3 的值 = 300

相关文章