Switch is more efficient than nested if or if - else in java

Q.  Switch is more efficient than nested if or if - else in java.
- Published on 22 Jul 15

a. True
b. False

ANSWER: True
 

    Discussion

  • Prajakta Pandit   -Posted on 14 Dec 15

    - The above statement is true.

    - A switch statement is faster than or equivalent to if-else, because the compiler generates a jump table for a switch during the compilation.

    - Switch is more readable, in comparison to if-else statement.

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)