Alternative to switch case
I'm sure this is a problem that almost everyone has dealt with:
Any suggestions on how to work a switch statement with a string?
I have a string array, where I want to base my switch on the first element.
The first element can have about 25+ different values. This makes using a hashcode a bit on the awkward side, since there will be no way to keep track of what each case is for. (Well placed comments would do it, but doesn't help much with making the code readable.)
Should I make an enum for all possible values and have a call to assign one for my switch. This seems like a bit of overkill.
Or is there something else that may work better?
use if loops or make ur own class
you can do this way -
1. use if..else..if statement
2. to comparing string object use :- stringObj1.compareTo(stringObj2)
or u can write ur own class and mention if else statements and while using it make it like stitch statement,
in C switch statement is internally multiple if statements , in Java I have not tried yet. just check it.