Java Hashmap interview questions

Page 1

JAVA HASHMAP INTERVIEW QUESTIONS WWW.CODESPAGHETTI.COM


INTERVIEW QUESTIONS

JAVA HASHMAP

INTERVIEW PROGRAMS

INTERVIEW ALGORITHMS


TOP THREE HASHMAPÂ INTERVIEW QUESTIONS


HOW TO DESCRIBE HASHMAP IN INTERVIEWS

-HashMap implements Map interface and maintains key and value pairs. -HashMap internally works on the principle of Hashing -HashMap can only contain unique keys and only one null key. -HashMap methods are nonsynchornized. -HashMap lookups are O(1) in the average case, and O(n) in the worst case


HOW HASHMAP WORKS INTERNALLY HashMap works on the principle of Hashing. To understand Hashing , we should understand the three terms first -Hash Function -Hash Value -Bucket


What is Hash function? hashCode() method which returns an integer value is the Hash function. The important point to note that, this method is present in Object class. This is the code for the hash function(also known as hashCode method) in Object Class : public native int hashCode(); What is Hash value? HashCode method return an int value.So the Hash value is just that int value returned by the hash function.


What is bucket? A bucket is used to store key value pairs. A bucket can have multiple key-value pairs. In hash map, bucket used is simply a linked list to store objects . So how does hashMap works internally? We know that Hash map works on the principle of hashing which means HashMap get(Key k) method calls hashCode method on the key object and applies returned hashValue to its own static hash function to find a bucket location(backing array)


HASMAP VSÂ HASHTABLE


READ 50+ HASHMAP INTERVIEW QUESTIONS AT: HTTP://WWW.CODESPAGHETTI.COM/JAVA-HASHMAP-INTERVIEW-QUESTIONS/

THANK YOU CODE SPAGHETTI


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.