• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generics

 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ques from Examlab...
output is
{<L>=<O>}???
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
output is
{<L>=<O>}???


Do you have a question to go along with the code ? What output were you expecting ?
 
maggie karve
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why is it not printing all the values???
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Analyze this code and discern the output. That will answer your question

 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 317
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you will change your code like


It will give the result you were expecting
 
Simran Dass
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

This is a question on Collections.
Kindly put it under the topic Collections and not Generics next time.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic