import java.util.HashMap; public class HashMapExample { public static void main(String[] args) { HashMapmarks = new HashMap<>(); marks.put("John", 80); marks.put("Smith", 90); marks.put("Tom", 85); boolean result = marks.containsKey("Tom"); System.out.println("Result: " + result); // Output: Result: true } }
import java.util.HashMap; public class HashMapExample { public static void main(String[] args) { HashMapThis example demonstrates the usage of the containsKey() method in HashMap to check if the key "grapes" is present in the map or not. The output of the code is "Result: false" as the key "grapes" is not present in the map. Package library: java.utilfruits = new HashMap<>(); fruits.put("apple", "red"); fruits.put("banana", "yellow"); fruits.put("orange", "orange"); boolean result = fruits.containsKey("grapes"); System.out.println("Result: " + result); // Output: Result: false } }