Below you can see my code. It reads words from dictionary and copy words that match specific patern to test.txt. My qusetion is how to sort words in test.txt first by LENGTH and
Add all your words to a list then sort using a comparator:
public static final Comparator wordComparator = new Comparator()
{
@Override
public int compare(String o1, String o2)
{
if(o1.length() == o2.length()) return o1.compareToIgnoreCase(o2);
else return o1.length() - o2.length();
}
};
ArrayList tmp = new ArrayList<>();
//Add words
Collections.sort(tmp, wordComparator);