How to Add an Item in a HashMap in Java


In this example, we will learn the method to add an item in a HashMap in Java.

Source Code

package com.beginner.examples;

import java.util.HashMap;

public class AddHashMap {
  public static void main(String[] args) {
    HashMap maps = new HashMap();
    maps.put("A", "a"); // add an item
    System.out.println(maps); 
  }
}

Output:

{A=a}

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments