I am told to have a list of words sorted by length, and those that have the same length are sorted by alphabetical order. This is what I have for the method that does that s
you want to use a string comparator that compares by length 1st. like so:
public class LengthFirstComparator implements Comparator {
@Override
public int compare(String o1, String o2) {
if (o1.length()!=o2.length()) {
return o1.length()-o2.length(); //overflow impossible since lengths are non-negative
}
return o1.compareTo(o2);
}
}
then you could simply sort your Strings by calling Collections.sort(yourStringList, new LengthFirstComparator());