- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 for the existence of a key in Java IdentityHashMap
Use the containsKey() method to check whether a particular key exists in IdentityHashMap or not.
Create a IdentityHashMap
Map<String, Integer> m = newIdentityHashMap<String, Integer>(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450);
Now, let’s say we need to check whether key 7 exists or not. For that, use the containsKey() method like this
m.containsKey(“7”)
The following is an example to check for the existence of a key in IdentityHashMap
Example
import java.util.*; public class Demo { public static void main(String[] args) { Map<String, Integer> m = newIdentityHashMap<String, Integer>(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450); System.out.println("IdentityHashMap elements
"+ m); System.out.println("Size = " + m.size()); System.out.println("Is key 7 in the Map? " + m.containsKey("7")); } }
Output
The output is as follows
IdentityHashMap elements {2=200, 4=150, 9=350, 7=90, 10=450, 6=50, 5=110, 8=250, 1=100, 3=300} Size = 10 Is key 7 in the Map? True
- Related Articles
- Check for the existence of a value in Java IdentityHashMap
- Fetch the value for a specific key in Java IdentityHashMap
- Check for the existence of key in an object using AngularJS
- Checking for Key/Value Existence in Perl Hash
- Test for existence of nested JavaScript object key in JavaScript
- How to check the Existence of a File using Java?
- Check existence of an element in Java ArrayList
- Check whether IdentityHashMap empty or not in Java?
- Get the size of the IdentityHashMap in Java
- Return a shallow copy of IdentityHashMap in Java
- Check the HybridDictionary for a specific key in C#
- Create IdentityHashMap in Java
- Clone IdentityHashMap in Java
- IdentityHashMap class in Java
- Get the set of values in Java IdentityHashMap

Advertisements