我有一张词频图Map<String, Integer>
。我需要制作一组最少出现的单词。假设最低出现的词都出现了两次,我需要将所有这些重复出现的词做一组。到目前为止,我有:
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;
}
这对我来说似乎有点令人费解。是否有本地收集工具来完成这项工作?