Saturday, April 27, 2019

what will be the output of following java code?

Problem statement:
what will be the output of the following java code?
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3. import java.util.HashMap;

  4. public class Solutions{
  5.     public static void main(String[] args) {
  6.         HashMap<Integer, String> m = new HashMap<>();
  7.         m.put(1001,"A");
  8.         m.put(1002,"B");
  9.         Collections.unmodifiableMap(m);
  10.         m.put(1001,"C");
  11.         System.out.println(m);
  12.     }
  13. }
Output: {1001=C, 1002=B}

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...