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

java hashmap set value

myMap.put(key, value);
Comment

PREVIOUS NEXT
Code Example
Java :: remove duplicates from arraylist in android 
Java :: what does setFocusable do in java 
Java :: Java @Deprecated annotation 
Java :: change color in recyclerview 
Java :: how to sort a list in java 
Java :: java printwriter create file 
Java :: how to start array index from 1 in java 
Java :: java creating an object 
Java :: Java Expression statements 
Java :: java collectors mapping 
Java :: Java Singleton Class Syntax 
Java :: convert json to xml in java 
Java :: How to Initialize Arrays in Java? 
Java :: java append to array 
Java :: android hide and show bottom navigation 
Java :: remove an element from an array in java 
Java :: method overriding in java 
Java :: static method in non static class java 
Java :: java "-" 
Java :: pass data to layout from navigation android studio 
Java :: fragment to activity typecasting 
Java :: random class in java 
Java :: show menuitem when menu hovered javafx 
Java :: instance block in java 
Java :: url to json 
Java :: reactive kafka 
Java :: java %2C 
Java :: Person[] people = in java 
Java :: using addition to multiply in java 
Java :: where do you use overriding in framework 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =