14.11. The switch Statement

The switch statement transfers control to one of several statements depending on the value of an expression.

SwitchStatement:    switch ( Expression ) SwitchBlockSwitchBlock:    { SwitchBlockStatementGroupsopt SwitchLabelsopt }SwitchBlockStatementGroups:    SwitchBlockStatementGroup    SwitchBlockStatementGroups SwitchBlockStatementGroupSwitchBlockStatementGroup:    SwitchLabels BlockStatementsSwitchLabels:    SwitchLabel    SwitchLabels SwitchLabelSwitchLabel:    case ConstantExpression :    case EnumConstantName :    default :EnumConstantName:    Identifier

The type of the Expression must be char, byte, short, int, Character, Byte, Short, Integer, String, or an enum type (§8.9), or a compile-time error occurs.

Get The Java® Language Specification, Java SE 7 Edition, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.