Search a key in linkedhashmap in java

We can use containsKey() method to search a key in treemap in java.

containsKey(Object k): Returns true if this map contains specified key otherwise returns false.


public boolean containsKey(Object k)


package com.w3spoint;
import java.util.LinkedHashMap;
public class Test {
	public static void main(String args[]){
		LinkedHashMap<Integer, String> linkedHashMap = 
				new LinkedHashMap<Integer, String>();
		//Add objects to the HashSet.
		linkedHashMap.put(4, "Roxy");
		linkedHashMap.put(2, "Sunil");
		linkedHashMap.put(5, "Sandy");
		linkedHashMap.put(1, "Munish");
		linkedHashMap.put(3, "Pardeep");
		//Print the LinkedHashMap object.
		System.out.println("LinkedHashMap elements:");
		System.out.println("LinkedHashMap contains key 4:" + linkedHashMap.containsKey(4));


LinkedHashMap elements:
{4=Roxy, 2=Sunil, 5=Sandy, 1=Munish, 3=Pardeep}
LinkedHashMap contains key 4:true
Please follow and like us:
Content Protection by