gudii9
asked on
tree map implementation
Hi,
My eclipse produced below two TreeMap Impementation codes when i tried
TreeMap<Integer, String> ts=new TreeMap<Integer, String>(theComparator);
TreeMap<Integer, String> tm=new TreeMap<Integer, String>();
What is the difference between above two. theComparator is used for the value right?(which happened to be String here)
I need bit more clarity on above two. please advise
My eclipse produced below two TreeMap Impementation codes when i tried
TreeMap<Integer, String> ts=new TreeMap<Integer, String>(theComparator);
TreeMap<Integer, String> tm=new TreeMap<Integer, String>();
What is the difference between above two. theComparator is used for the value right?(which happened to be String here)
I need bit more clarity on above two. please advise
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Thats what mccarl said wasn't it?
ASKER
TreeMap
public TreeMap(Comparator<? super K> comparator)
Constructs a new, empty tree map, ordered according to the given comparator. All keys inserted into the map must be mutually comparable by the given comparator: comparator.compare(k1, k2) must not throw a ClassCastException for any keys k1 and k2 in the map. If the user attempts to put a key into the map that violates this constraint, the put(Object key, Object value) call will throw a ClassCastException.
Parameters:
comparator - the comparator that will be used to order this map. If null, the natural ordering of the keys will be used.
TreeMap
public TreeMap(Map<? extends K,? extends V> m)
Constructs a new tree map containing the same mappings as the given map, ordered according to the natural ordering of its keys. All keys inserted into the new map must implement the Comparable interface. Furthermore, all such keys must be mutually comparable: k1.compareTo(k2) must not throw a ClassCastException for any keys k1 and k2 in the map. This method runs in n*log(n) time.
Parameters:
m - the map whose mappings are to be placed in this map
Throws:
ClassCastException - if the keys in m are not Comparable, or are not mutually comparable
NullPointerException - if the specified map is null
TreeMap
public TreeMap(SortedMap<K,? extends V> m)
Constructs a new tree map containing the same mappings and using the same ordering as the specified sorted map. This method runs in linear time.
what is the difference between above three.
all looks similar to me.
what is meaning of < and ? and >
please advise
Please read tutorial on generics first.
Generics
Generics
ASKER
i wonder why they write sentences so looooooooooong which makes it hard to understand and digest in API. please advise
They don't. They make them as short as possible and as precise as possible.
You problem is probably the opposite of what you think it is: i.e. you'd benefit from repetition, expansion and variation to provide clarification
You problem is probably the opposite of what you think it is: i.e. you'd benefit from repetition, expansion and variation to provide clarification
You need to take time to read the subject.
Posting in forums and bouncing questions of people is not the way to go about doing it. You wont benefit from it unless you put the hard work to do some background reading.
Posting in forums and bouncing questions of people is not the way to go about doing it. You wont benefit from it unless you put the hard work to do some background reading.
ASKER
They make them as short as possible and as precise as possible.
i get they are short and precise. But readability of the new comers is challenge right. I read 3 times still trying to understand.
ASKER
Map<? extends K,? extends V> m
comma means two parameters it has right one is key and other is value But Parameters says only one as below
Parameters:
m - the map whose mappings are to be placed in this map
comma means two parameters it has right one is key and other is value But Parameters says only one as below
Parameters:
m - the map whose mappings are to be placed in this map
ASKER
i looked below link on generics which is more undersandable to me.
http://www.journaldev.com/1663/java-generics-tutorial-example-class-interface-methods-wildcards-and-much-more
So the API they are using upperbound syntax.
http://www.journaldev.com/1663/java-generics-tutorial-example-class-interface-methods-wildcards-and-much-more
So the API they are using upperbound syntax.
ASKER
i see by KEYS not VALUES