I am trying to keep an ordered list without repeated elements. I have created a TreeSet, but I see that it inserts repeated elements and I do not see clearly why. If I use TreeSet.contains () it does not detect it either. Here the code
TreeSet array = new TreeSet(new Comparator<Integer>(){
@Override
public int compare(Integer o1, Integer o2) {
return o1>o2?o1:o2;
}
});
int valor =0;
for(int scores_i=0; scores_i < n; scores_i++){
valor=in.nextInt();
if (!array.contains(valor)){
array.add(valor);
}
}
The values that I enter are 100,100,50,25