Easy Tutorial
❮ Net Url Header String Optimization ❯

Java Example - continue Keyword Usage

Java Examples

The Java continue statement is used to end the current loop iteration and proceed to the next iteration, meaning only the current iteration is terminated, not all iterations, and subsequent iterations continue to execute.

The following example demonstrates the use of the continue keyword to skip the current iteration and start the next one:

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 the above code is:

Found 2 'h' characters
hello how are you.

Java Examples

❮ Net Url Header String Optimization ❯