- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Remove value from HashMap in Java
Use the remove() method to remove value from HashMap.
First, create a HashMap and add elements −
HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));
Now, remove a value, let’s say with key “Wallet” −
Object ob = hm.remove("Wallet");
The following is an example to remove a value from HashMap −
Example
import java.util.*; public class Demo { public static void main(String args[]) { // Create hash map HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200)); System.out.println("Map = "+hm); Object ob = hm.remove("Wallet"); System.out.println("Map after removing an element= "+hm); } }
Output
Map = {Backpack=1200, Belt=600, Wallet=700} Map after removing an element= {Backpack=1200, Belt=600}
- Related Articles
- Java Program to remove key value pair from HashMap?
- Remove all values from HashMap in Java
- Java Program to remove a key from a HashMap
- C++ Remove an Entry Using Value from HashMap while Iterating over It
- Set Date value in Java HashMap?
- Java Program to remove a key from a HashMap only if it is associated with a given value
- Java Program to Get key from HashMap using the value
- Remove a value from TreeMap in Java
- Remove a value from Java LinkedHashMap
- Extract values from HashMap in Java
- remove null value from a String array in Java
- How to remove data from hashmap to arraylist for listview in Android?
- Retrieve all the keys from HashMap in Java
- How to use null value as key in Java HashMap
- HashMap in Java

Advertisements