I want to make something looked like an dictionary, where there are a lot of words starting with different letters. How can I use Collections.sort()
so that I can sort all the words and print the info about the letters that are next. The result should look like:
Words starting by A:
AAA
AAB
ABB
ABC
Words starting by B:
BAA
BAB
BBB
BBC
That's my code:
public Dictionary(){
private ArrayList<String> words;
@Override
public String toString(){
Collections.sort(words);
String str = "";
for(int i = 0; i< words.size() ; i++){
str += words.get(i) + "\n";
}
return str;
}
}