No you can’t . The case labels of a switch need to be compile time evaluable constant expressions with an integral type.
Read moreHow do you use a string in a switch case?
String in Switch Statement Example 1
Read moreDo switch cases work with strings?
It is recommended to use String values in a switch statement if the data you are dealing with is also Strings . The expression in the switch cases must not be null else, a NullPointerException is thrown (Run-time). Comparison of Strings in switch statement is case sensitive.5 Tem 2019
Read moreWhich data type Cannot be used in switch Java?
The switch statement doesn’t accept arguments of type long, float, double,boolean or any object besides String .
Read moreCan we use contains in Java?
The contains() method in Java is used to search the substring in a given String . Returns: If the substring is found in the specified String, then it returns a true value; otherwise, it returns a false value.
Read moreDoes Java case work with strings?
Java (before version 7) does not support String in switch/case . But you can achieve the desired result by using an enum. Learn to use else .
Read moreCan String be used in switch case in Java?
Yes, we can use a switch statement with Strings in Java .5 Tem 2019
Read more