入力テキスト ファイルを取得して配列に変換し、配列を並べ替えてから、各単語の頻度を取得します。多くのものをインポートせずに、頻度に従ってそれらを最高から最低までソートする方法を理解できません(これが私がやろうとしていることです):
//find frequencies
int count = 0;
List<String> list = new ArrayList<>();
for(String s:words){
if(!list.contains(s)){
list.add(s);
}
}
for(int i=0;i<list.size();i++){
for(int j=0;j<words.length;j++){
if(list.get(i).equals(words[j])){
count++;
}
}
System.out.println(list.get(i) + "\t" + count);
count=0;
}
これは、ソートされていない順序で頻度の単語を返します。次に例を示します。
the 3
with 7
he 8
等
これを次のようにソートしたい:
he 8
with 7
the 3