Java Map merge value

Description

Java Map merge value


import java.util.HashMap;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    Map<Integer, String> map = new HashMap<>();

    map.put(1, "11");
    map.put(2, "22");
    map.put(3, "33");
    map.put(4, "44");
    map.put(5, "55");
    map.put(6, "66");
    /*from  w w  w  .j  a  va  2  s .com*/

    map.merge(3, "val9", (value, newValue) -> value.concat(newValue));
    System.out.println(map.get(3)); 

    map.merge(3, "concat", (value, newValue) -> value.concat(newValue));
    System.out.println(map.get(3)); 
  }

}



PreviousNext

Related