Java switch vs if/else

in java •  7 years ago 

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

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!