Java Hasmap Remove Elements

[Solved] Java Hasmap Remove Elements | Solidity - Code Explorer | yomemimo.com
Question : Java Remove HashMap Elements

Answered by : samer-saeid

import java.util.HashMap;
class Main { public static void main(String[] args) { HashMap<Integer, String> languages = new HashMap<>(); languages.put(1, "Java"); languages.put(2, "Python"); languages.put(3, "JavaScript"); System.out.println("HashMap: " + languages); // remove element associated with key 2 String value = languages.remove(2); System.out.println("Removed value: " + value); System.out.println("Updated HashMap: " + languages); }
}

Source : | Last Update : Wed, 01 Jun 22

Question : Java Hasmap Remove Elements

Answered by : softhunt

import java.util.*;
public class hashmapeg3{ public static void main(String args[]){ HashMap<Integer,String> map=new HashMap<Integer,String>();//Creating HashMap map.put(1,"Cat"); //Put elements in Map map.put(2,"Dog"); map.put(3,"Markhor"); map.put(4,"Peacock"); System.out.println("HashMap after put(): "); for(Map.Entry m : map.entrySet()){ System.out.println(m.getKey()+" "+m.getValue()); }
// remove element associated with key 2 String value = map.remove(2); System.out.println("Removed value: " + value); System.out.println("Updated HashMap: "); for(Map.Entry m : map.entrySet()){ System.out.println(m.getKey()+" "+m.getValue()); }
}
}

Source : https://softhunt.net/java-hashmap-with-examples/ | Last Update : Tue, 17 May 22

Answers related to java hasmap remove elements

Code Explorer Popular Question For Solidity