containsKey(Object): This method is available in java.util.LinkedHashMap class of Java.
Syntax:
boolean java.util.HashMap.containsKey(Object key)
This method takes one argument. This method returns true if this map contains a mapping for the specified key.
Parameters: One parameter is required for this method.
key: The key whose presence in this map is to be tested.
Returns: true if this map contains a mapping for the specified key.
Exceptions: NA
Approach
Java
import java.util.LinkedHashMap;public class LinkedHashMapcontainsKey {public static void main(String args[]) {LinkedHashMap<String, Integer> linkedHashMap =new LinkedHashMap<String, Integer>();linkedHashMap.put("Java", 1);linkedHashMap.put("Hello", 2);Object key = "Hello";System.out.println(linkedHashMap.containsKey(key));}}
Output:
true
No comments:
Post a Comment