wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "generics" Watch "generics" New topic
Author

generics

maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
Ques from Examlab...
output is
{<L>=<O>}???
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

output is
{<L>=<O>}???


Do you have a question to go along with the code ? What output were you expecting ?


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
maggie karve
Ranch Hand

Joined: Dec 29, 2009
Posts: 186
why is it not printing all the values???
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

Analyze this code and discern the output. That will answer your question

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

Your overridden method is always returning 0,


which means whatever will you pass for TreeMap both the values will be equal. So each time when you pass the new element to TreeMap, it will compare the key and will found them same (Because of compare method implementation) and it will replace the existing value with new one.

If you try it with



as the first entry of map then the output will be

{<T>=<Y>}

Harpreet Singh janda
Ranch Hand

Joined: Jan 14, 2010
Posts: 317

If you will change your code like


It will give the result you were expecting
Simran Dass
Ranch Hand

Joined: Jan 09, 2010
Posts: 183

This is a question on Collections.
Kindly put it under the topic Collections and not Generics next time.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: generics
 
Similar Threads
confusing Generics
HashMap prob
hash code question from K&B book
HashMap: keySet() and values order
hashmap doubt