Use this comparator implementation:
@Override
public int compare(String o1, String o2) {
if(o2.equals("XX")) {
return o1.equals("XX") ? 0 : 1;
} else if (o1.equals("XX")) {
return -1;
}
return o1.compareTo(o2);
}
Reason: Beyond the question when to use -1 or 1 it is important to guarantee a clear order for all possible tuples of o1 and o2, see javadoc:
[...] The implementor must ensure that sgn(compare(x, y)) == -sgn(compare(y, x)) for all x and y. (This implies that compare(x, y) must throw an exception if and only if compare(y, x) throws an exception.)
The implementor must also ensure that the relation is transitive: ((compare(x, y)>0) && (compare(y, z)>0)) implies compare(x, z)>0. [...]