Java switch case with multiple values

Let’s learn java switch case with multiple values.

Java switch case with multiple values

Let’s learn to check multiple values in single switch statement or expression.

Here’s an example on switch case with multiple values.

public class SwitchCaseMultipleValues
{
   public static void main(String[] args)
   {
      int number = 1;
      switch(number)
      {
         case 1: case 2:
             System.out.println("number 1");
             System.out.println("number 2");
             break;
         case 3:
             System.out.println("number 3");
             break;
         default:
             System.out.println("number is not 1, 2 or 3");
      }
   }
}


Output:

number 1
number 2


Also read – ArrayList in java