# switch Java Keyword

The switch statement is used to select execution of one of multiple code blocks based on an expression.

## Examples

      int arg = <some value>;
      switch (arg)
      {
         case 1:
            <statements>
            break;
         case 2:
            <statements>
            break;
         default:
            <statements>
            break;
      }

      char arg = <some value>;
      switch (arg)
      {
         case 'y':
         case 'Y':
            <statements>
            break;
         case 'n':
         case 'N':
            <statements>
            break;
         default:
            <statements>
            break;
      }

## Remarks

- The switch condition must evaluate to a byte, char, short or int.

- A case block does not have an implicit ending point. A break statement is typically used at the end of each case block to exit the switch statement.

- Without a break statement, the flow of execution will flow into all following case and/or default blocks.

Related Topics

break Java Keyword

case Java Keyword

default Java Keyword