#/help
1 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @calm mortar! Please use
/closeor theClose Postbutton above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
If you use a TreeMap, you need to tell it how to sort keys
which you can do by making the key type (Contact) implement Comparable (meaning two contacts can be compared to each other)
alternatively, you can use a custom Comparator
or not use a TreeNao
@limber stirrup
Thank you for the help!
Like this?
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
yes but make sure your compareTo method properly compares the contacts
Yes I did it seems like it works
it should
- return 0 if they are equal
- return a value >0 if this is "bigger" than other
- return a value <0 if this is "smaller" than other
There is a possibility you'll explain me why it's necessary?
I don't understand why this compareTo function fixed everything.
I mean, why I even needed it?
why the line: java "if(map.containsKey(contacts[i])) { map.remove(contacts[i]); }
"
needed compareTo in orther to work
If it's too much that's ok, I'll try to search about it
This message has been formatted automatically. You can disable this using /preferences.
Yes
TreeMap getskey and value and automatically sort it with the other ones compared to the key
exactly
It's a red-black tree as i know
and if you want to sort something, you need to know what's before and what's after
right
you can't sort stuff if you don't have a way to know which order to put it
and if the keys are Comparable, you are specifying an order
Right
Understood
that's why it gave the error, because in every insertion of key&value it needs to compare
yes
Got it
Thank you very much for your help
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.