In “How HashMap works in Java“, we learned the internals of HashMap or ConcurrentHashMap class and how they fit into the whole concept. But when the interviewer asks you about HashMap related concepts, he does not stop only on the core concept. The discussion usually goes in multiple d...
9. Difference betweenHashtableandHashMapin Java? (former is thread-safe and doesn't allow null, later is not thread-safe, former is also slow because of whole locking of Map, whileHashMapis fast because of no locking,read more) 10. Difference betweenArrayListandLinkedListin Java? (former i...
In my previous post related to “How HashMap works in java“, I explained the internals of HashMap class and how they fit into whole concept. But when interviewer ask you about HashMap related concepts, he does not stop only on core concept. The discussion usually goes in multiple directio...
8) What is intern() in java? 9) Which collection classes will allowed NULL? 10) What happen if we add same key with different values to HashMap? 11) What is the use of load factor? 12) How to make HashMap thread safe? 13) what is the parent class of exception in java? 14) W...
Explain the difference betweenpublic,private,protected, anddefaultaccess modifiers in Java. String,StringBuilder,StringBuffer HashMap,LinkedHashMap,ConcurrentHashMap What is the purpose of theExceptionclass in Java? TheExceptionclass is the base class for all exception types in Java. It represents an ...
Java Collections Interview Questions and AnswersWhat are Collection related features in Java 8? Java 8 has brought major changes in the Collection API. Some of the changes are: Java Stream API for collection classes for supporting sequential as well as parallel processing Iterable interface is ...
HashMap How do you handle exceptions in Java? This is one of the crucial Java developer interview questions if you want robust and error-free code. Try-catch blocks is used for exception handling in Java. A code that raises an exception is enclosed in the ‘try’ block. The corresponding...
Why isStringa popularHashMapkey in Java? Since aStringobject is immutable, its hashcode is cached at the time of creation and it doesn’t need to be calculated again. This makes it a great candidate for the key in a Map since its processing is faster than otherHashMapkey objects. ...
Sowhen we store an item in HashSet, item is stored askeyin Map and the existing object as thevalue. publicbooleanadd(Ee){returnmap.put(e,PRESENT)==null;} I will highly suggest you read this post:How HashMap works?This post will help you answer all theHashMaprelated questions very comf...
Q. What are the methods used to implement for key Object in HashMap? 1. equals() and 2. hashcode() Class inherits methods from the following classes in terms of HashMap java.util.AbstractMap java.util.Object java.util.Map Q. What is difference between the Inner Class and Sub Class? Ne...