I have the following for loop, where the StringList is
List<String> stringList= new ArrayList<String>();
for (String elementList : stringList)
{
if (elementList =="string1")
{
Key=1;
}
else if (elementList =="string2")
{
Key=0;
}
// do some code here
}
If the (stringList) includes 20,000 string words. The repeating of the words "string1" and "string2" is 10,000 for each in (stringList). it takes time to check every word in the for loop.
How can we make the for loop iterate only two times because there are only two types of words which are "string1" and "string2" regardless of it's repeating in the (stringList)