Java switch vs if/else

If a switch contains more than five items, it's implemented using a lookup table or a hash list (jump table). This means that all items get the same access time, compared to a list of if/else where the last item takes much more time to reach as it has to evaluate every previous condition first.

But these sorts of micro-optimizations are unlikely to affect the performance of your code. Implement whichever design is clearer and more maintainable

H2
H3
H4
3 columns
2 columns
1 column
Join the conversation now
Logo
Center