目录

boolean containsKey(Object key)

描述 (Description)

containsKey(Object key)方法用于测试指定的对象引用是否是此标识哈希映射中的键。

声明 (Declaration)

以下是java.util.IdentityHashMap.containsKey()方法的声明。

public boolean containsKey(Object key)

参数 (Parameters)

key - 这是要检查的可能键。

返回值 (Return Value)

如果指定的对象引用是此映射中的键,则方法调用返回“true”。

异常 (Exception)

NA

例子 (Example)

以下示例显示了java.util.IdentityHashMap.containsKey()的用法

package com.iowiki;
import java.util.*;
public class IdentityHashMapDemo {
   public static void main(String args[]) {
      // create identity hash map
      IdentityHashMap ihmap = new IdentityHashMap();
      // populate the map
      ihmap.put(1, "java");
      ihmap.put(2, "util");
      ihmap.put(3, "package");
      // check if key 3 exists
      boolean isavailable = ihmap.containsKey(3);
      System.out.println("Is key '3' exists: " + isavailable); 
   }    
}

让我们编译并运行上面的程序,这将产生以下结果。

Is key '3' exists: true
↑回到顶部↑
WIKI教程 @2018