+ 1
Why IF ELSE statement is preferred over,SWITCH CASE statement
9 ответов
+ 16
It is only preferred if it provides better readability.
And if you use more than 3 nested if - it does ^^
+ 14
@chirag String is possible in switch with Java8.
+ 12
@Arpit I don't understand your answer.
+ 11
Published a code example:
https://code.sololearn.com/cQBKg9QBBy1R/?ref=app
Check comments at the very top of the code.
+ 9
if-else can be used in many places where u cannot use switch case.
like,if u want to compare string,floating point numbers etc. u cannot use switch case.
also switch case can only compare if the value is equal not < or > .
so if-else is preferred.
+ 8
@tashi N oh thanks!! i didnt know about java8!!
+ 6
If else can use difficult expressions.Example,
in switchcase , case x+8 is not possibe, whereas its possible in if else.
0
what's is after does
0
Hi, I am new to JAVA, and didn't know about the switch case limitations. I tend to write for readability since performance is rarely an issue with the fast computer speeds these days. Can anyone provide examples of IF statements vs. CASE statements? It would be very helpful...