Java autoboxing unboxing null pointer exception

Question

What is the output of the following code?

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

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

    m.put("CSS", 42);
    m.put("HTML", 3);
    m.put("Java", 1);
    /*from   w w w  . j  a  va  2 s. c  o m*/
    Integer i = m.get("asdf");
    System.out.println(i+1);
    
  }
}


Exception in thread "main" java.lang.NullPointerException
	at Main.main(Main.java:13)

Note

The following code assigned null to i,

Integer i = m.get("asdf");



PreviousNext

Related