Can I use OR operators in Java switches?

I am wondering if I can use orin switch-casein Java?

Example

switch (value)
{
   case 0:
      do();
      break;

   case 2 OR 3 
      do2();
      break;
} 
+5
source share
1 answer

There is no "or" operator in a case statement in Java. However, you can allow one case to “fail” with another by omitting the statement break:

switch (value)
{
   case 0:
      do();
      break;

   case 2:  // fall through
   case 3:
      do2();
      break;
} 
+17
source

All Articles