Info on TreeMap
I'm having difficultly understanding how this piece of code works...
TreeMap object ?myMap:
TreeMap<String, Integer> myMap =new TreeMap<String, Integer>();
myMap.put(搚es?1);
myMap.put(搉o?1);
myMap.put(搈aybe?1);
myMap.put(搕rue?1);
myMap.put(揻alse?1);
I'm trying to find the outputs of these two statements...
System.out.println(myMap.keySet()); //keys only
System.out.println(myMap.entrySet());//keys and values
I'm not following the logic at all, can someone help clarify...Thx...
Cremer77
[617 byte] By [
Cremer77a] at [2007-10-2 1:58:11]

What exactly is it that you don't follow? The first thing returns a Set viewof all keys, while the second statement returns the entire TreeMap asan EntrySet containing tuples of keys and values.kind regards,Jos
JosAHa at 2007-7-15 19:39:24 >

> What exactly is it that you don't follow? The first
> thing returns a Set view
> of all keys, while the second statement returns the
> entire TreeMap as
> an EntrySet containing tuples of keys and values.
>
> kind regards,
>
> Jos
First, thanks for you help...From what I understand the first question is asking for specified view of all keys, in which case, "yes, no, maybe, true, false..."
And for the the second, it's asking for everything, correct? I hope I'm the right track...
Regards,
Cremer77
> First, thanks for you help...From what I understand the first question is
> asking for specified view of all keys, in which case, "yes, no, maybe,
> true, false..."
Yep, correct. All the keys are presented as a Set of keys.
> And for the the second, it's asking for everything, correct? I hope I'm
> the right track...
Yep, correct too. The key/value pairs are represented by a single
Map.Entry object and all those things are collected in another Set again.
kind regards,
Jos
JosAHa at 2007-7-15 19:39:24 >
