Java Examples - continue Keyword Usage
The Java continue statement is used to end the current loop and proceed to the next loop. That is, only this iteration ends, not the entire loop; subsequent iterations still continue.
The following example uses the continue keyword to skip the current loop and start the next iteration:
Main.java file
public class Main {
public static void main(String[] args) {
StringBuffer searchstr = new StringBuffer("hello how are you. ");
int length = searchstr.length();
int count = 0;
for (int i = 0; i < length; i++) {
if (searchstr.charAt(i) != 'h')
continue;
count++;
searchstr.setCharAt(i, 'h');
}
System.out.println("Found" + count
+ "h characters");
System.out.println(searchstr);
}
}
The output of running the above code is:
发现 2 个 h 字符 hello how are you.Other Extensions
Java Examples