Given:
import java.util.Iterator; import java.util.TreeMap; import java.util.TreeSet; public class Main { public static void main(String[] args) { TreeMap<String, String> tm = new TreeMap<String, String>(); TreeSet<String> ts = new TreeSet<String>(); String[] k = { "1", "b", "4", "3" }; String[] v = { "a", "d", "3", "b" }; for (int i = 0; i < 4; i++) { tm.put(k[i], v[i]);/*from ww w .j av a 2s . co m*/ ts.add(v[i]); } System.out.print(tm.values() + " "); Iterator it2 = ts.iterator(); while (it2.hasNext()) System.out.print(it2.next() + "-"); } }
Which of the following could be a part of the output? (Choose two.)
A and G are correct.
TreeMap.values()
returns the values associated with sorted keys (in this case, "naturally sorted" keys).
TreeSet iterators use the sorting sequence defined by the instance of TreeSet being used.
In this case, the TreeSet was built using "natural ordering.".