Home » Core Java » util » HashMap

HashMap

HashMap changes in Java 8

The way java.util.HashMap entries are indexed and stored has changed in the Java 8 update. Hash elements use balanced trees instead of linked lists under certain circumstances now. All these is what this article is about. The main idea is that when the number of items in a hash is larger than a certain value, the hash will change from ...

Read More »

Java Hashmap Example

HashMap is a member of the Java Collection Framework and is a very common way to collect and retrieve data. HashMap represents a data structure that offers key-value pairs storing, based on hashing. In this example we are going to show how we can create a simple HashMap and a HashMap where multiple values correspond to a key, as well ...

Read More »

Remove mapping from HashMap example

This is an example of how to remove mapping from a HashMap, that is removing a key value pair from a HashMap. Removing mapping from a HashMap implies that you should: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the remove(Object key) API method of HashMap, to remove ...

Read More »

Remove all mappings from HashMap example

This is an example of how to remove all mappings from a HashMap, that means removing all key value pairs in a HashMap. Removing all key value pairs from a HashMap implies that you should: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the clear() API method of ...

Read More »

HashMap Iterator example

In this example we shall show you how to use a HashMap Iterator. To use a HashMap one should perform the following steps: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the entrySet() API method of the HashMap to get a Set of all the entries (key – ...

Read More »

Get size of HashMap example

With this example we are going to demonstrate how to get the size of a HashMap, that is the number of key value pairs that the HashMap contains. In short, to the size of a HashMap you should: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the size() ...

Read More »

Get Set view of HashMap keys example

This is an example of how to get a Set view of HashMap keys. Getting a Set view of HashMap keys implies that you should: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the keySet() API method of HashMap to get a Set containing all keys in the ...

Read More »

Check value existence in HashMap example

In this example we shall show you how to check a value existence in HashMap. To check if a value exists in a HashMap one should perform the following steps: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the containsValue(Object key) API method of the HashMap with a ...

Read More »

Check key existence in HashMap example

With this example we are going to demonstrate how to check a key existence in a HashMap. In short, to check if a key exists in a HashMap you should: Create a new HashMap. Populate the hashMap with elements, with the put(K key, V value) API method of HashMap. Invoke the containsKey(Object key) API method of the HashMap. The method ...

Read More »

Want to take your Java skills to the next level?

Grab our programming books for FREE!

Here are some of the eBooks you will get:

  • Spring Interview QnA
  • Multithreading & Concurrency QnA
  • JPA Minibook
  • JVM Troubleshooting Guide
  • Advanced Java
  • Java Interview QnA
  • Java Design Patterns