Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

update value in hashmap java

map.replace(key, map.get(key) + 1);
//or
map.put(key, map.get(key) + 1);
Comment

Java Change HashMap Value

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("Original HashMap: " + languages);

    // change element with key 2
    languages.replace(2, "C++");
    System.out.println("HashMap using replace(): " + languages);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: javax.xml.bind does not exist 
Java :: CellStyle change backgroung color java 
Java :: fullscreen java jframe 
Java :: java import decimalformat 
Java :: sleep for milliseconds in java 
Java :: android studio linearlayout set margin 
Java :: from string to double andoird studio 
Java :: A failure occurred while executing com.android.build.gradle.internal.tasks.Workers$ActionFacade java.lang.OutOfMemoryError (no error message) 
Java :: android parse date 
Java :: java declare multilayred array values 
Java :: jakkala siva venkata deepesh 
Java :: check if char is in char array java 
Java :: java get specific element from arraylisb 
Java :: textarea user select disable java swing 
Java :: intent android open activity 
Java :: collection vs collections 
Java :: java write string 
Java :: lombok get error in extended classes¨ 
Java :: java create set with values 
Java :: jpa tree structure 
Java :: Get the first Monday of a month in Java 
Java :: traversing 2d array java 
Java :: checkindex java 
Java :: best ascii art characters 
Java :: java string multiply 
Java :: access main class from another class spigot 
Java :: onclicklistener in android studio 
Java :: java coding problems 
Java :: decomposer chaine de caractère java 
Java :: java for loop 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =