0

I know this question has been treated before but I've read questions and tried to fix my own with no result, I think I'm missing something with the TreeMap or Map implementation...

if(arme != null){
    if(!hommesArmes.containsKey(arme)){
        System.out.println(hommesArmes.containsKey(arme));
        hommesArmes.put(arme, new TreeSet<Homme>());
        System.out.println(hommesArmes.containsKey(arme));
    }
    hommesArmes.get(arme).add(homme);
}

Why do I get false twice when I run this? I've tried with Integer instead of Arme and it worked, I don't understand what I'm doing wrong.

  • 2
    The class used as the key (Arme) doesn't implement Comparable correctly. Or the comparator you used when constructing the TreeMap is wrong. Post the relevant code. – JB Nizet Nov 11 '18 at 16:41
  • That's exactly what I was going to write, I just discovered I had a problem with the Comparator object I passed to its constructor. – Axel Carré Nov 11 '18 at 16:44
  • 1
    What kind of object have you assigned to arme? – Sandeepa Nov 11 '18 at 16:44

1 Answers1

0

I had a problem with the Comparator object I passed to the constructor of my TreeMap.