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...
implemented on top of HashTable. HashMap stores key-value pairs and doesn’t guarantee the order of the elements. It is also not synchronized. When you create a HashMap in Java then its’ initial capacity is 16 and its’ load factor is 0.75. When the map resizes, its’ capacity ...
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...
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...
Hash set Linked Hash Set Tree Set Maps: Hash Map Hash Table TreeMap Linked Hashed Map Queue: Priority Queue Q #26) What is meant by Ordered and Sorted in collections? Answer: Ordered: It means the values that are stored in a collection is based on the values that are added to the co...
How HashMap works in Java?HashMap stores key-value pair in `Map.Entry` static nested class implementation. HashMap works on hashing algorithm and uses hashCode() and equals() method in `put` and `get` methods. When we call `put` method by passing key-value pair, HashMap uses Key ...
9. How HashSet Store Unique Items? We must know that aHashMapstores key-value pairs, with one condition that keys will be unique.HashSet uses unique keys feature of the Map to ensure the uniquenessof items it stores. InHashSetclass, a map declaration is as below: ...
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. ...
1 What are new Java8 Features? 2 Difference between GET & POST METHODS? 3 Difference between forward() method & SendRedirect() method? 4 Difference between HashMap and HashTable? 5 Difference between HashSet and TreeSet? 6 What is meant by Collections in Java? 7 What is meant by Ordered...
Slightly more advanced would be to use a ConcurrentHashMap to ensure thread safety of the internal data structure, but this doesn’t get around the fundamental problem of races between the get() and put() calls. To solve that, we need to synchronize on the individual account. One possible...