Check if a particular value exists in LinkedHashMap in Java

In this tutorial, we will learn how to Check if a particular value exists in LinkedHashMap in Java ?

LinkedHashMap in Java is Hash table and LinkedList implementation of the Map interface, with predictable iteration order. This implementation differs from HashMap in that it maintains a doubly-linked list running through all of its entries. It maintains a linked list of the entries in the map, in the order in which they were inserted. This allows insertion-order iteration over the map. That is, when iterating through a collection-view of a LinkedHashMap, the elements will be returned in the order in which they were inserted. To access a value in LinkedHashMap, you need to have a key.

To check if a particular value exists in LinkedHashMap or not, LinkedHashMap class in Java provides a method containsValue(). We will use this method to check if particular value exists in LinkedHashMap. The syntax of this method is:

Syntax of containsValue() method:

Parameters:
value – The value whose presence in this map is to be tested.

Returns:
true if the value exists in map.

Example:

 

Output:

 

Related posts

Leave a Comment