How do if-else and switch differ in Java, and when should you reach for each one?
Both choose between alternatives, but they suit different shapes of decision. An if-else chain is a general conditional: it evaluates boolean expressions, supports ranges and compound conditions, and nests as deeply as you like. A switch dispatches on a single value against a fixed list of constants, which makes it easier to read when you have six or more mutually exclusive cases.
Three practical differences. First, a switch on a String or an enum compares against known constants using equals semantics, so you cannot write a range or a compound condition inside a case label; for that you fall back to if-else. Second, a switch expression must be exhaustive, which turns a whole class of missing-branch bugs into compile errors. Third, an if-else chain silently falls through to the end when no branch matches, while an arrow-labelled switch case does nothing at all unless you provide a default.
The switch expression is the better default for value selection. It produces a value instead of assigning into a variable in every branch, and the arrow form removes fall-through entirely, because each case ends at the arrow rather than at the next label.
Where if-else still wins: conditions that are not equality tests, ranges such as score >= 90, and any decision with fewer than three branches. Switching on two or three values is usually clearer as an if-else than as a switch with a single case.