TreeMap#containsKey return false just after put

161 views Asked by At

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.

1

There are 1 answers

0
Axel Carré On

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