The containskey method is used to determine whether the map set object contains the specified key name.
Syntax Boolean containskey (Object key)
Return Value: If the map set contains the specified key name, true is returned; otherwise, false is returned.
Parameter: key is the key name object of the map set to be queried.
In this example, the hashmap class is used to create a map set object, add several elements to the set, and call the containskey method to check whether the specified key name is included.
Public static void main (string [] ARGs ){
Map map = new hashmap ();
Map. Put ("apple", "fresh apple"); // Add data to the list
Map. Put ("computer", "computer with excellent configuration"); // Add data to the list
Map. Put ("book", "books stacked into mountains"); // Add data to the list
String key = "book ";
Boolean contains = map. containskey (key );
If (contains ){
System. Out. println ("include key name in map set" + key );
} Else {
System. Out. println ("the key name is not included in the map set" + key );
}
}
Containskey Method -- determines whether the specified key name is included