Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Java Hashmap Replace 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());    
   }  
  // change element with key 2
    map.replace(2, "Wolf");
    System.out.println("HashMap using replace(): ");
       for(Map.Entry m : map.entrySet()){    
    System.out.println(m.getKey()+" "+m.getValue());    
   } 
}  
}
Comment

java hashmap replace

Hashmap<String, String> map = new HashMap<>();
map.put("Hello", "you");
map.replace("Hello", "World");
map.get("Hello"); // World
Comment

PREVIOUS NEXT
Code Example
Java :: java exponencial 
Java :: has been compiled by a more recent version of the Java Runtime (class file version 55.0) 
Java :: java zahlen runden auf 1 nachkommastelle 
Java :: how to create dynamic string array in java 
Java :: switch en java 
Java :: how to add multiple action listeners java swing 
Java :: java string 
Java :: exception in java 
Java :: android studio json parser 
Java :: instance of 
Java :: change fab image programatically 
Java :: GetMapping("/rest/v1/books") in spring rest api 
Java :: null java 
Java :: scaletype android dynamic 
Java :: refreshing method() android studio webview 
Java :: java get parent class 
Java :: How to change integers into float in java 
Java :: how to use iterator in java 
Java :: set style programmatically android 
Java :: precision java 
Java :: control structures in java 
Java :: broadcast receiver for no interner android studio 
Java :: java collectors mapping 
Java :: how to use java 
Java :: switch java 
Java :: join arrays in java 
Java :: java replaceall single character 
Java :: jre in java 
Java :: android videoview not smooth for mp4 
Java :: androi amterila inpout dialgue to get inouti diaogue 
ADD CONTENT
Topic
Content
Source link
Name
1+3 =