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 literals 
Java :: round int java 
Java :: authentication in spring boot 
Java :: instanceof java 
Java :: jre in java 
Java :: java convert int to string 
Java :: get the average of an array in java 
Java :: lopping rows rethinkdb 
Java :: how to et curent directory in java 
Java :: android java how to stop users fromgoing back too much 
Java :: customized cache key java 
Java :: android sqlite insert or replace 
Java :: getsmallestnumber 
Java :: Does JVM create object of Main class (the class with main())? 
Java :: what is a callable in java 
Java :: square oot of 154 
Java :: REGEX ___ get length of array in java 
Java :: how to accept only numbers and whitespace in java 
Java :: okhttp Updating Views on UIThread 
Java :: string to integer online 
Java :: PlatformException (PlatformException(unknown, java.lang.Exception: Client is offline, {code: unknown, message: java.lang.Exception: Client is offline}, null)) 
Java :: another name for coffee 
Java :: about action Listioner in java Swing 
Java :: javax.servlet.Filter 
Java :: java lambda expression in priorityqueue 
Java :: a to double 
Java :: Add space to the left and right sides of a cell 
Java :: copy array of objects in java 
Java :: A method that returns a stream of JUnit Arguments 
Java :: selenium code for login 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =