+ 7
Can the switch statement be used with strings??
8 Respostas
+ 5
Mohd Shahzer
String in Switch Case in Java. Beginning with JDK 7, we can use astring literal/constant to control a switch statement, which is not possible in C/C++.
Using a string-based switch is an improvement over using the equivalent
sequence of
if/else statements.
source: https://www.geeksforgeeks.org/string-in-switch-case-in-java/
I hope I was helpful
+ 8
@Alessio
Yes you were
Thanks
+ 4
As of now, there is no known way of using strings with switch case. You could use single character constants instead, or maybe some character at some position in the string.
+ 2
Mohd Shahzer you are welcome!
+ 2
Not possible till now with C++ .
But you can use a single character instead of string in switch statement.
+ 1
We can't use a switch statement with strings in c++. you can only use integer, short, long, character. I think its the same for all the other programming languages too.
correct me if i am wrong.
+ 1
Bennett Post 😊 thanks 😊
+ 1
c#,java string base switch allowed.