Computer Science, asked by sreekutty75, 1 year ago

What is the difference between if statement and switch statement in java?​

Answers

Answered by yashthoapte11
1

I will just say that they are both decision making statement their syntax is different

Answered by anupamajeevan
0

Switch statement is used in java to compare different values(cases) of a particular variable while if..else.. is used to control the flow of execution based on relational logic you define.

Important point to note here is that switch can not evaluate relational logic, i.e. you can not use relational operators in switch statement therefore making if..else.. more flexible in terms of condition checking.

Bear in mind if you only want to use have equality checks of primitive types, String and enums then using switch is better because switch uses table lookups which are almost always better performers than a relation evaluation.

Similar questions