-1
我正在制作一个小程序,其中的一部分针对阵列列表中的每个竞争对手的能力,对不同竞争者进行迭代,以将不同竞争者排序为映射。除了一个问题之外,它似乎起作用。第一条if语句不起作用。任何被分类为beginer的竞争者都不会被分类为beginerResults,而是被归类为standardResults。其他人工作正常。有什么建议么?使用迭代将阵列列表排序映射到地图
public void sort()
{
for (Golfer rating : competitors)
{
if (competitors.getScore()== "beginer")
{
beginerResults.put(competitor.getName());
}
if (competitors.getScore()== "Intermediate")
{
intermediateResults.put(competitor.getName());
}
else
{
expertResults.put(age.getName());
}
}
}
您比较字符串错误,请参阅邹邹提供的链接。另外,在你的例子中没有Maps,一个'Map.put'需要一个'key'和一个'value',也许你的意思是'Set'? – Taylor
您从不使用当前迭代的变量('rating'),只是您正在迭代的集合(“竞争对手”)。 –