This Java Example shows how to know that an Key is exists in the specified TreeMap object in java.
Check an Key Is Exists in Java TreeMap Example
This Java Example shows how to know that an Key is exists in the specified
TreeMap object in java. To get the Key from TreeMap object we use boolean
containsKey(key) method. This method returns true if Map contains the
specified key otherwise returns false.
Example: ContainskeyInTreeMap.java
package devmanuals.com; import java.util.*; public class ContainskeyInTreeMap { public static void main(String args[]) { TreeMap Tmap = new TreeMap(); Tmap.put("Gyan", "Singh"); Tmap.put("Ankit", "Kumar"); Tmap.put("Arunesh", "Kumar"); Tmap.put("Anand", "Nagar"); Tmap.put("Ram", "Prakash"); boolean bool = Tmap.containsKey("Arunesh"); System.out.println("Is Arunesh is exists in map : " + bool); } }
Output:
Is Arunesh is exists in map : true |
[ 0 ] Comments