-5

I found a Java question J couldn't understand what should be answer

The TreeMap and LinkedHashMap classes:

  1. enable iteration of a map's entries based on the insertion order of elements only.
  2. enable iteration of a map's entries based on natural ordering of keys only.
  3. enable iteration of a map's entries in a deterministic order.
  4. enable iteration of a map's entries based either natural ordering of keys OR natural ordering of values depending on the arguments sent to the contructor.
Crazyjavahacking
  • 9,343
  • 2
  • 31
  • 40
SidJj
  • 142
  • 1
  • 1
  • 11
  • 6
    and the question is...how to pass my exam? – fantarama Jul 10 '15 at 14:28
  • 1
    Lol @fantarama but indeed right ! – Ouney Jul 10 '15 at 14:30
  • Hint: Some of the statements apply to `TreeMap`, but not to `LinkedHashMap`. Other statements apply to `LinkedHashMap`, but not to `TreeMap`. Only one of the above four statements is correct about both `TreeMap` **and** `LinkedHashMap`. You need to find which one. – Sergey Kalinichenko Jul 10 '15 at 14:32

1 Answers1

0

In Java:

  1. TreeMap is a Map that automatically sorts the Map entries according to its natural ordering using Comparable<T> interface
  2. LinkedHashMap is Map that guarantees that the entries will be returned in the same order as they were added
Crazyjavahacking
  • 9,343
  • 2
  • 31
  • 40