In: Computer Science
public class Main{
public static void main (String[] args) {
Map<Integer, String> ssnMap =
new HashMap<Integer, String>();
ssnMap.put (8675309,"Jenney");
ssnMap.put (42, "Answer to Everything");
ssnMap.put (8675309, "Stacy");
ssnMap.put (1006, "Peter");
System.out.println(ssnMap.get (8675309));
}
}
What is the output of the above code. Why?
input code:
import java.util.*;
public class Main{
public static void main (String[] args)
{
/*create a hash map*/
Map<Integer, String> ssnMap = new HashMap<Integer,
String>();
/*add value into make*/
ssnMap.put (8675309,"Jenney");
ssnMap.put (42, "Answer to Everything");
ssnMap.put (8675309, "Stacy");
ssnMap.put (1006, "Peter");
/*print the value of 8675309*/
System.out.println(ssnMap.get (8675309));
}
}
output:
code:
explain:
=>in this program we make one hashmap
=>than add 4 keys and ints value in map.
=>than we print the value which key is 8675309.
=>and we enter stacy with 8675309 so we get that output