This Java Example shows how to know that an Key is exists in the specified HashMap object in java.
Check an Key Is Exists in Java HashMap Example
This Java Example shows how to know that an Key is exists in the
specified HashMap object in java. To get the Key from HashMap object
we use boolean containsKey(key) method. This method returns
true if list contains the specified key otherwise returns false.
Example: ContainskeyInHashMap.java
package devmanuals.com; import java.util.*; public class ContainskeyInHashMap { public static void main(String args[]) { HashMap hm = new HashMap(); hm.put(1, "Gyan"); hm.put(2, "Ankit"); hm.put(3, "Arun"); hm.put(4, "Anand"); hm.put(5, "Ram"); boolean bool = hm.containsKey("2"); System.out.println("Is 2 is exists in HashMap : " + bool); } }
Output:
Is 2 is exists in HashMap : false |
[ 0 ] Comments