Can we add duplicate keys in a HashMap ? What will happen if we attempt to add duplicate values ?
Questions
Search
List By Company
List By Topic
Legacy
Tests
Repository
DashBoard
Java
Java 8
Java 7
Java Abbreviations
OCJP / SCJP
Class List
New in Java 8
Java Exceptions
Spring Exceptions
Java Enums
Java 8 Lambda
Java 8 java.time
Big Data
Best Of Java
Discussion
Search
Subscribe
Search Interview Questions
More than 3000 questions in repository.
There are more than 900 unanswered questions.
Click here
and help us by providing the answer.
Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company
Label / Company / Text
Search
Submit Question
Interview Questions and Answers
Q1.
Can we add duplicate keys in a HashMap ? What will happen if we attempt to add duplicate values ?
Ans. No, We cannot have duplicate keys in HashMap. If we attempt to do so , the previous value for the key is overwritten.
Help us improve. Please let us know the company, where you were asked this question
:
Like
Discuss
Correct / Improve
 java   collections   hashmap   map   hashtable
Correction
Duplicate of Another Question
Company where this question was Asked
Suggestion
Try 1 Question(s) Test
If we try to add duplicate key to the HashMap, What will happen ?
It will throw an exception.
It won't add the new Element without any exception.
The new element will replace the existing element.
Compiler will identify the problem and will throw an error.
Related Questions
Difference between HashMap and Hashtable?
Difference between TreeMap and HashMap ?
Can you provide some implementation of a Dictionary having large number of words ?
How is Hashmap internally implemented in Java ?
What is a ConcurrentHashMap ?
Collections.sort can only be performed on ..
a. Set
b. List
c. Map
d. Any Collection implementation
Why HashTable has been deprecated ?
What is the difference between List, Set and Map ?
or
What are the different Java Collections Interfaces ?
Can we use null as a key for a map collection ?
What is comparator interface used for ?
Help us and Others Improve. Please let us know the questions asked in any of your previous interview.
Any input from you will be highly appreciated and It will unlock the application for 10 more requests.
Company Name:
Questions Asked: