2 回答
TA贡献2039条经验 获得超7个赞
字符串" Berlin "
和"Berlin"
不相等(即使您比较它们时忽略大小写。第一个包含前导空格和尾随空格。删除它们或替换runner.getLocation()
为runner.getLocation().trim()
.
TA贡献1735条经验 获得超5个赞
将方法更新updateLocation为:
public static void updateLocation(ArrayList<Runner> runners){
for(Runner runner : runners){
if(runner.getLocation().trim().equalsIgnoreCase("Berlin")){
runner.setLocation("Berlin, Germany");
}else if(runner.getLocation().trim().equalsIgnoreCase("Shanghai")){
runner.setLocation("Shanghai, China");
}else if(runner.getLocation().trim().equalsIgnoreCase("London")){
runner.setLocation("London, England");
}else if(runner.getLocation().trim().equalsIgnoreCase("Athens")){
runner.setLocation("Athens, Greece");
} else if(runner.getLocation().trim().equalsIgnoreCase("Eugene")){
runner.setLocation("Eugene, South Africa");
} else if(runner.getLocation().trim().equalsIgnoreCase("Seville")){
runner.setLocation("Seville, France");
}else if(runner.getLocation().trim().equalsIgnoreCase("Lausanne")){
runner.setLocation("Lausanne, Spain");
}else if(runner.getLocation().trim().equalsIgnoreCase("Rieti")){
runner.setLocation("Rieti, Australia");
}else if(runner.getLocation().trim().equalsIgnoreCase("Atlanta")){
runner.setLocation("Atlanta, USA");
}
}
}
搜索字符串包含空格,而expected string没有
添加回答
举报