Is it possible to convert an if statement into a switch statement in java?
Is it possible to convert an if statement into a switch statement in java?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First of all, it’s technically a switch block. Second of all, yes it is possible, but extremely unnecessary. However, if you want to do it, here is one way you could make the conversion…
Of course, if you are comparing something other than strings you would use the
==operator.The two are also interchangeable, but only if you’re working with
charsorintsand only one condition is being tested.