Java Map use null value as key

Description

Java Map use null value as key

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

public class Main {
  public static final void main(String[] args) {
    Map<String,String> map = new HashMap<>();
    map.put("CSS", "CSS");
    System.out.println("Size = " + map.size());
    map.put(null, "HTML");
    System.out.println("Size = " + map.size());
    // ww w  .  ja  va 2 s  . c  om
    System.out.println("map.get(null) = " + map.get(null));
    
    map.put(null, "Java");
    System.out.println("map.get(null) = " + map.get(null));
  }
}



PreviousNext

Related