[go: up one dir, main page]

0% found this document useful (0 votes)
56 views18 pages

Hashmap Explained

HashMap in Java stores data as key-value pairs and allows retrieving values by key. It contains unique keys, with duplicate keys replacing existing values. HashMap is non-synchronized and maintains no order.

Uploaded by

raja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views18 pages

Hashmap Explained

HashMap in Java stores data as key-value pairs and allows retrieving values by key. It contains unique keys, with duplicate keys replacing existing values. HashMap is non-synchronized and maintains no order.

Uploaded by

raja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 18

HashMap in Java 

stores the data in


(Key, Value) pairs, and you can
access them by an index of another
type (e.g. an Integer).

HASHMAP One object is used as a key (index) to


another object (value).

If you try to insert the duplicate key


in HashMap, it will replace the
element of the corresponding key.
This This is by editing
What is HashMap and why is it used?

HashMap is a data structure that uses a hash function


to map identifying values, known as keys, to their
associated values.

It contains “key-value” pairs and allows retrieving


value by key. Map myhash = Collections.
• Java HashMap is a class which is used to perform operations such as
inserting, deleting and locating elements in a map.

• We create a map, where we pass two kinds of values which are 'key'
and 'value'.
• What are the different types of HashMap?

• All three classes HashMap, TreeMap and LinkedHashMap implements java.


util. Map interface, and represents mapping from unique key to values.

• What is a real life example of HashMap?

• Real-world application of HashMap example: In storing the records of the


employees of a company where employee ID is stored as a key and employee
data is stored as a value in the HashMap.
• What is HashMap with example?

• HashMap in Java stores the data in (Key, Value) pairs, and you can access
them by an index of another type (e.g. an Integer).

• One object is used as a key (index) to another object (value).

• If you try to insert the duplicate key in HashMap, it will replace the element
of the corresponding key.
HASHMAP IN JAVA
LOAD FACTOR IN HASHMAP IN JAVA
WITH EXAMPLES
JAVA HASHMAP
• Java HashMap class implements the Map interface which allows us to store
key and value pair, where keys should be unique.

• If you try to insert the duplicate key, it will replace the element of the
corresponding key.
• It is easy to perform operations using the key index like updation, deletion, etc.

• HashMap in Java is like the legacy Hashtable class, but it is not synchronized.
• It allows us to store the null elements as well, but there should be only one
null key.

• It inherits the AbstractMap class and implements the Map interface.


POINTS TO REMEMBER
• Java HashMap contains values based on the key.

• Java HashMap contains only unique keys.

• Java HashMap may have one null key and multiple null values.

• Java HashMap is non synchronized.

• Java HashMap maintains no order.

• The initial default capacity of Java HashMap class is 16 with a load factor of
0.75.
JAVA HASHMAP EXAMPLE
JAVA HASHMAP EXAMPLE TO
REMOVE() ELEMENTS
Basic Operations on Java HashMap

• The HashMap class provides various methods to perform different


operations on hashmaps. We will look at some commonly used arraylist
operations in this tutorial:

• Add elements
• Access elements
• Change elements
• Remove elements
NICE REFERENCES YOUTUBE
URLS
• https://youtu.be/udB-dHqS3ng
• https://youtu.be/H62Jfv1DJlU

You might also like