One way would be to check if x
is empty outside of the loop, and set it if it is.
public String getTeam()
{
String x = "";
for(Team tm : allTeams.values())
{
if(tm.getStatus().equals("Added"))
{
x = x + tm.toString();
}
}
if (x.isEmpty())
{
x = "there are no teams in your league";
}
return x;
}
I assumed you meant to return x
, not temp
, as temp
isn't defined here.