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