I currently have a program that works on an array by using a for loop to iterate through the array with an embedded if statement that matches the element in the array to the one I'm looking for. I need to modify this so that it will find the second occurrence of the same element. Ideas on how to do this?
String[] myStringArray = {"a", "b", "c", "a", "d", "e", "f"};
for(int i=0; i<myStringArray.length; i++) {
if(myStringArray[i].equalsIgnoreCase("a") {
//do something
}
}
As noted, this will find the first a and I will do work on it, however the second a needs to be acted upon also.