How to Remove an Item From a HashMap in Java


In this example we will show the method to remove an item from a HashMap in Java.

Source Code

package com.beginner.examples;

import java.util.HashMap;

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

Output:

{B=b}

References

Imported packages in Java documentation:

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments