bugl
bugl
HomeLearnPatternsPathsSearch
HomeLearnPatternsPathsSearch

Loading lesson path

Learn/Java/Java Reference
Java•Java Reference

Java HashMap putAll() Method

Flash cards

Review the key moves

1/4
Core idea

What is the main idea behind Java HashMap putAll() Method?

Lesson checks

Practice each idea before moving on

Short Mimo-style checks built from this lesson's code, terms, and sequence.

1Quick choice

Which statement best captures the main point of this lesson?

2Fill blank

Complete the missing token from the example code.

___ java.util.HashMap;
3Order

Put the learning moves in the order that makes the concept easiest to apply.

The putAll() method writes all of the entries from another map into the map.
Definition and Usage
Java HashMap putAll() Method

❮ HashMap Methods

Example

import java.util.HashMap;
public class Main {
  public static void main(String[] args) {
    HashMap<String, String> capitalCities = new HashMap<String, String>();
    capitalCities.put("England", "London");
    capitalCities.put("Germany", "Berlin");
    capitalCities.put("Norway", "Oslo");
    capitalCities.put("USA", "Washington DC");
    HashMap<String, String> moreCities = new HashMap<String, String>();
    moreCities.put("Canada", "Ottawa");
    moreCities.put("Japan", "Tokyo");
    capitalCities.putAll(moreCities);
    System.out.println(capitalCities);
  }
}

Definition and Usage

The putAll() method writes all of the entries from another map into the map. If entries exist with the same keys then the values of these entries will be changed.

One of the following

public void putAll(Map
map )

K and V refer to the data types of the keys and values of the map.

Parameter Values

ParameterDescription
mapRequired. Another map containing entries to be added to the map.

Technical Details

Throws:NullPointerException - If the map argument is null .

Previous

Java HashMap put() Method

Next

Java HashMap putIfAbsent() Method