adplus-dvertising
frame-decoration

Question

What is the output of below snippet?
public class Demo
{
  public static void main(String[] args)
  {
  Map<Integer, Object> sampleMap = new TreeMap<Integer, Object>();
  sampleMap.put(1, null); 
  sampleMap.put(5, null); 
  sampleMap.put(3, null); 
  sampleMap.put(2, null); 
  sampleMap.put(4, null); 
 
       System.out.println(sampleMap);
   }
}

a.

{1=null, 2=null, 3=null, 4=null, 5=null}

b.

{5=null}

c.

Exception is thrown

d.

{1=null, 5=null, 3=null, 2=null, 4=null}

Answer: (a).{1=null, 2=null, 3=null, 4=null, 5=null}

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of below snippet?

Similar Questions

Discover Related MCQs

Q. If large number of items are stored in hash bucket, what happens to the internal structure?

Q. How can we remove an object from ArrayList?

Q. How to remove duplicates from List?

Q. How to sort elements of ArrayList?

Q. When two threads access the same ArrayList object what is the outcome of the program?

Q. How is Arrays.asList() different than the standard way of initialising List?

Q. What is the difference between length() and size() of ArrayList?

Q. Which class provides thread safe implementation of List?

Q. Which of the below is not an implementation of List interface?

Q. What is the worst case complexity of accessing an element in ArrayList?

Q. When an array is passed to a method, will the content of the array undergo changes with the actions carried within the function?

Q. What is the default clone of HashSet?

Q. Do we have get(Object o) method in HashSet.

Q. What does Collections.emptySet() return?

Q. What are the initial capacity and load factor of HashSet?

Q. What is the relation between hashset and hashmap?

Q. Set has contains(Object o) method.

Q. What is the difference between TreeSet and SortedSet?

Q. What happens if two threads simultaneously modify TreeSet?

Q. What is the unique feature of LinkedHashSet?