java object switch case code example

Example 1: java switch case

switch(x){
	case(0):		//if x == 0
    	//do some stuff
    	break;
    //add more cases
  default:			//when x does not match any case
    //do some stuff
    break;
}

Example 2: java switch on what classes

A switch works with the byte, short, char, and int primitive data types.
It also works with enumerated types (discussed in Enum Types), the String
class, and a few special classes that wrap certain primitive types: 
Character , Byte , Short , and Integer (discussed in Numbers and Strings).