January 2014
Intermediate to advanced
736 pages
70h 43m
English
As of Java SE 7, you can use Strings in a switch statement’s controlling expression and in case labels. For example, you might want to use a city’s name to obtain the corresponding ZIP code. Assuming that city and zipCode are String variables, the following switch statement performs this task for three cities:
switch( city ) { case "Maynard": zipCode = "01754" ; break ; case "Marlborough": zipCode = "01752" ; break ; case "Framingham": zipCode = "01701" ; break ; } // end switch
Read now
Unlock full access