How Java HashMap Works

How Java HashMap Works


Can you explain how Java HashMap works? A Map in Java stores key and volume pairs.
Keys have to be unique, and knowing the key lets you find the value. I knew that much. A HashMap is basically an
array with lots of numbers, and the key lets you identify which value in that array or
map of values to use. The HashMap class is how you implement the
map interface. Why not just use arrays or strings to store
values? Using a hash table with the map interface
standardizes the time it takes to use operations like get and put. HashMaps may be used to pull up account balances,
last time someone logged in or other stored values. I never thought though that the speed
at which it is retrieved mattered. You create a HashMap with the command HashMap
string integer cache equals new hashmap string integer () semicolon. I thought there were other ways to create
one. Java will let you create a new HashMap copying
data from another HashMap. Or create a Hashtable. But how does the HashMap work? You retrieve values from a HashMap by naming
the string key, then writing string value equals map.get key. Then you tell it system
out print in key plus key plus value plus value. It should then print out the value of that
key location as an output. That’s right. The HashMap stores the values,
and Java will retrieve the value referenced by the key like picking out the inventory
on shelf 83, slot 5. I’ve heard there were other benefits to using
a HashMap. Since the code knows exactly where to look
for values, it retrieves values in the Hashmap faster than other methods. And it won’t error
out unless the value in the Hashmap is somehow an error in and of itself. With Java, that’s not hard to do. HashMaps and HashTables also do not care about
duplicate values, as long as the keys are different. They could all be zero, as long as they all
have separate addresses. And the Java HashMap is the way it references
those unique addresses.

17 thoughts on “How Java HashMap Works”

  1. Sasidhar reddy Chavva

    may be you should avoid the audio to be system generated by some software. i would have been more convenient if the audio is of some human .

  2. I like this! The animation is great fun and even though the audio is strange at first, I actually grew to like it. Thanks!

  3. This would be infinitely better if you used human voices instead of some software. Because of the unclear audio, I stopped watching and learned nothing.

  4. "A Map in Java stores key and volume pairs" that would be Key and VALUE pairs. If you are here studying for an interview, this explains how to use a hash map, not how it works. You interviewer will likely press you for a deeper understanding about buckets, overriding .equals() and .hashcode(), and why that is significant. All maps support put and get, so research what is special about the hash implementation specifically.

  5. hashmaps aren't arrays at all. why do you call them "arrays with lots of numbers." that's not a good description.

  6. nothing in this video makes any sense, except for the java crap. Why are they having this meeting? What are these other people doing here? How does this relate to the pie chart? I don't understand

  7. Илья Коннов

    lmfao the guy is able to paint and animate people but isn't able to read for them wtf. Just use your own voice, come on dude

Leave a Reply

Your email address will not be published. Required fields are marked *