+ 2

What is difference between if else and switch case in java.

15th Jun 2018, 2:48 AM
Maninder $ingh
Maninder $ingh - avatar
5 Respuestas
0
Maninder Singh in a switch statement you can only check one variable for certain cases. in if else statements you can check for multiple conditions for example. hope that helps.
15th Jun 2018, 4:27 AM
MMJ
+ 2
MMJ It is not always faster. I did some code on an arduino and with 16 cases, the ifs were faster.
15th Jun 2018, 11:55 AM
Bebida Roja
Bebida Roja - avatar
0
I think switch searches the result by a hash, so for a lot of cases it is faster that if/else
15th Jun 2018, 3:04 AM
Bebida Roja
Bebida Roja - avatar
0
Switch can be used as if else and vice versa is also true. The performance may very. In small code the performance may not very that much but in large codes, switch is better.
23rd Jun 2018, 4:24 AM
Mihir Kumar
Mihir Kumar - avatar
0
my java error
25th Jun 2018, 1:42 AM
Muhammad Saiful
Muhammad Saiful - avatar