O'Reilly logo

The Java® Language Specification, Java SE 7 Edition, Fourth Edition by Alex Buckley, Gilad Bracha, Guy Steele, Bill Joy, James Gosling

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required