I want to be able to compare one string to all other strings sequentially and then move down to the next string and compare that strings to all the other strings below it.
Here is the code I have. It compares the first string correctly and finds no matches. However when the other for loop moves to the next value of i, everystring =1 and so does i so it compares itself. How can I go about moving the inner for loop one value each time I go through the other loop?
for (int everystring = 0; everystring < children.length; everystring++) {
String current = children[everystring].substring(0,
children[everystring].indexOf("_"));
for (int i = 1; i < children.length; i++) {
String innercurrent = children[i].substring(0,
children[i].indexOf("_"));
if (current.equalsIgnoreCase(innercurrent)) {
System.out.println("Match");
} else
System.out.println("No Match");
}
System.out.println();
}
loop always from 0 to
children.length[in inner loop], and add the following condition in the beginning of the inner loop:It will skip every iteration of the inner loop where
i == everything, so you will only check for strings that are unequal.Note however that you will check each 2 strings twice (for example: you will check
i == 1,everything == 2andi == 2, everything == 1If you don’t want it: iterate in inner loop from
everything + 1untilchildren.length