Take a look on the stop-condition found || counter < ArrayToSearch.size()
. What if you've found the needed element? In such a case found
will be true
and stop
-condition will always be true
, your loop will never stop. The correct loop is the following:
public static boolean Search(ArrayList<String> ArrayToSearch,String word)
{
String temp;
for(int counter = 0;counter < ArrayToSearch.size();counter++)
{
temp = ArrayToSearch.get(counter);
if(temp.equals(word.toLowerCase()))
{
position = counter;
return true;
}
}
return false;
}