私は単語の周波数Map<String, Integer>
の地図を持っています。私は、出現頻度の低い単語のセットを作る必要があります。最も低い出現単語がすべて2回出現したとしましょう。これらの2回の出現単語のセットを作成する必要があります。これまでのところ、私は持っています:地図の最小値を持つキーをセットに移す
public Set findRarest()
{
int occurrence = 1000; //high initial value for word length
for (Map.Entry<String,Integer> item : wcMap.entrySet())
{
if (item.getValue() > occurrence); //most likely for performance
else if (item.getValue() == occurrence)
{
rarest.add(item.getKey());
}
else //found new lowest count
{
rarest.clear();
rarest.add(item.getKey());
}
}
return rarest;
}
これは私にちょっと混乱しているようです。これを行うためのネイティブコレクションツールはありますか?
そうでもありません。グアバの 'Multiset'は多少厄介なものにするかもしれませんが、これは基本的にそれを行う方法です - ' if(item.getValue()>オカレンス); '行を持つ理由はまったくありません。 –