protected int getGewichtung(String company)
{
int index;
for (HashMap<String,String> i : top3Compland)
{
String test = String.join(_name, i.keySet());
System.out.println(test);
if (test == company)
{
index = top3Compland.indexOf(i);
}
else
{
index = -5;
}
}
return index;
}
I have checked with print statements whether it is entering the for-loop at all. But all the keys are being printed out so it does enter it and also the conversion to a string does take place and as I am at first putting only valid strings to the function it also must enter the if statement for sure but if even it doesn't then it would be enter the else statement and initialize it with a number so it should't be complaining about the variable "index" possibly not being initialized. What am I overseeing?? Thank you for your help!
updated Version: I improved some flaws, but the same error is arising. But I cannot fathom a case in which index is not being initialized...
protected int getGewichtung(String company)
{
int index;
if (top3Compland.size() > 0 && top3Compland != null)
{
for (HashMap<String,String> i : top3Compland)
{
String test = String.join(_name, i.keySet());
System.out.println(test);
if (test.equals(company))
{
index = top3Compland.indexOf(i);
}
}
}
else
{
index = -5; //company not found
}
return index;
}