I have created a class with the objective of having a method, within that class that receives a String x, and than it goest through a loop to see if the string received matches with any of the Strings inside the String[]. Here is my code:
public class MatchCountry
{
public boolean findCountry(String a)
{
boolean match = false;
String [] euCountries = {"Albania", "Andorra", "Armenia", "Austria", "Azerbaijan", "Belarus", "Belgium", "Bosnia and Herzegovina",
"Bulgaria", "Croatia", "Cyprus", "Czech Republic", "Denmark", "Estonia", "Finland", "France", "Georgia", "Germany", "Greece",
"Holland", "Iceland", "Ireland", "Italy", "Latvia", "Liechtenstein", "Lithuania", "Luxembourg", "Macedonia", "Malta",
"Moldova", "Monaco", "Montenegro", "Netherlands", "Norway", "Poland", "Portugal", "Romania","Russia","San Marino",
"Serbia", "Slovakia", "Slovenia", "Spain", "Sweden", "Switzerland", "Turkey", "Ukraine", "United Kingdom", "Vatican City"};
int l = euCountries.length;
for (int i = 0; i < l; i++)
{
System.out.println(euCountries[i]);
if (a == euCountries[i])
match = true;
else
match = false;
}
return match;
}
public static void main (String args[])
{
MatchCountry mc = new MatchCountry();
boolean found = mc.findCountry("Portugal");
System.out.println(found);
}
}
Shouldn't this work? When I output the boolean found, it keeps giving me FALSE...