Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java Remove HashMap Elements

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);
  }
}
Comment

Java Hasmap Remove Elements

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());    
   }  
}  
}
Comment

PREVIOUS NEXT
Code Example
Java :: java boolean data type 
Java :: maths trivia in java 
Java :: how to remove last latter in word in java 
Java :: java how to split a string to array 
Java :: java garbage collection 
Java :: creating an object in java 
Java :: java code for logarithm 
Java :: The Longest Substring 
Java :: terminate function calling in java 
Java :: different constructiors in java and what they do explained 
Java :: navigation bottom android 
Java :: java hex to rgb 
Java :: navigation graph setup android 
Java :: android hide and show bottom navigation 
Java :: spring mvc 
Java :: array buffer 
Java :: why string is immutable in java 
Java :: java print array of objects 
Java :: lopping rows rethinkdb 
Java :: how does plus works in Java 
Java :: if else bedingungen java 
Java :: factorial recursion java 
Java :: calculate mcd in javsa 
Java :: Java try Keyword 
Java :: power of a number in java 
Java :: java fill in the code to read and store the next value in the array 
Java :: arraycopy merging arrays 
Java :: Algorithms - filtering 
Java :: pattern exercises for java 
Java :: os compatible java path separator 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =