#/help

1 messages · Page 1 of 1 (latest)

calm mortar
#

What is wrong with it?
I don't understand why I get an error

whole quarryBOT
#

This post has been reserved for your question.

Hey @calm mortar! Please use /close or the Close 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.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

limber stirrup
#

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

calm mortar
#

@limber stirrup
Thank you for the help!

Like this?

whole quarryBOT
limber stirrup
#

yes but make sure your compareTo method properly compares the contacts

calm mortar
#

Yes I did it seems like it works

limber stirrup
#

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
shrewd veldtBOT
#

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.

limber stirrup
#

Do you know what TreeMap does?

#

or how it is different from HashMap

calm mortar
#

Yes
TreeMap getskey and value and automatically sort it with the other ones compared to the key

limber stirrup
#

exactly

calm mortar
#

It's a red-black tree as i know

limber stirrup
#

and if you want to sort something, you need to know what's before and what's after

calm mortar
#

right

limber stirrup
#

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

calm mortar
#

Right

#

Understood
that's why it gave the error, because in every insertion of key&value it needs to compare

limber stirrup
#

yes

calm mortar
#

Got it
Thank you very much for your help

whole quarryBOT
# calm mortar 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.