Hello!
I have a Treemap, and use a comparator, co, in the declaration. The goal is to write the map out in String-size-order.
static JämförOrd co = new JämförOrd(); static NavigableSet<String> na = new TreeSet<>(co);
The comparator-class I've made look like this:
public class JämförOrd implements Comparator<String> { @Override public int compare(String s1, String s2) { if(s1.length()< s2.length()) { return -1; } else if (s1.length()>s2.length()) { return 1; } else return 0; } }
When I don't use the comparator, the treemap is written out, but not in string-size-order. When I use the comparator, only a small part of the words are written. Why is that?
/hank