単語頻度のマップがあります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;
}
これは私には少し複雑に思えます。これを行うためのネイティブの収集ツールはありますか?