
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check If a Particular Value Exists in Java LinkedHashMap
Use the containsValue() method to check whether a particular value exists in LinkedHashMap or not.
Create a LinkedHashMap −
LinkedHashMap<Integer, String> l = new LinkedHashMap<Integer, String>(); l.put(1, "Mars"); l.put(2, "Earth"); l.put(3, "Jupiter"); l.put(4, "Saturn"); l.put(5, "Venus");
Now, let’s say we need to check whether value “Saturn” exists or not. For that, use the containsValue() method like this −
containsValue("Saturn")
The following is an example to check if a particular value exists in LinkedHashMap −
Example
import java.util.*; public class Demo { public static void main(String[] args) { LinkedHashMap<Integer, String> l = new LinkedHashMap<Integer, String>(); l.put(1, "Mars"); l.put(2, "Earth"); l.put(3, "Jupiter"); l.put(4, "Saturn"); l.put(5, "Venus"); System.out.println("LinkedHashMap elements..."); System.out.println(l); System.out.println("\nDoes value Saturn exist in the LinkedHashMap map? "+l.containsValue("Saturn")); } }
Output
LinkedHashMap elements... {1=Mars, 2=Earth, 3=Jupiter, 4=Saturn, 5=Venus} Does value Saturn exist in the LinkedHashMap map? True
Advertisements