/help
What is wrong with it?
I don't understand why I get an error
20 Replies
⌛
This post has been reserved for your question.
Hey @Yarden! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
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
@dan1st | Daniel
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 contactsYes 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:
"
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
.Do you know what
TreeMap
does?
or how it is different from HashMap
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 orderRight
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.
Post Closed
This post has been closed by <@218019068219883520>.