Google News
logo
Java - Interview Questions
Can we use string for switch statement?
Yes to version 7. From JDK 7, we can use string as switch condition. Before version 6, we can not use string as switch condition.

   switch (str.toLowerCase()) // java 7 only!
   {
      case "a":value = 1;
break;
      case "b":value = 2;
        break;
   }
Advertisement