I have a method to compare two list of objects.
The objects are unique in both lists.
I doing it with 2 level nested for loops
I want to terminate the inner for loop's remaining cycles if two objects match correctly.
Is it possible to terminate the remaining iteration of a for loop in Java?!
Thanks
The Sample Code:
public class NestedForLoops {
public static void main(String[] args) {
String one = "abcdefgh";
String two = "ijkhmnop";
System.out.println(nestedForLoop(one, two));
}
public static String nestedForLoop(String one, String two)
{
String res = "";
for(int i = 0; i < one.length(); i++)
{
for(int j = 0; j < two.length(); j++)
{
if(one.charAt(i) == two.charAt(j)){
System.out.println(i + " " + j);
res += one.charAt(i);
continue;
}
}
}
return res;
}
}