Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Java

Idiom #232 Read a command line boolean flag

Print "verbose is true" if the flag -v was passed to the program command line, "verbose is false" otherwise.

import static java.lang.System.out;
public static void main(String[] args) {
    boolean b = false;
    for (String s : args)
        if (s.equals("-v")) {
            b = true;
            break;
        }
    out.printf("verbose is %s", b);
}
print("verbose is ${args.contains("-v")}");

New implementation...
< >
programming-idioms.org