I have this coding inside my java file .
This code basically receives an int value and sets a char value for an Object
Student st = new Student();
if (attributeName.equals("Grade")) {
int sidevalue = Integer.parseInt(attribute.getValue()); // This returns an int value , and this value needs to be converted into char later as shown
if(sidevalue==1)
st.grade=1;
else if(sidevalue==2)
st.grade=2;
else if(sidevalue==5)
st.grade=3;
}
class Student
{
char grade ;
}
A
switchcasecheck here statement could avoid multipleifelseindentation!There is no significant execution difference in running between
if-elseandswitch.Observed differences may be due to the sample space of the particular code you are running.
In the little code snippet you provide there is not a best choice, except that
switchstatement provides improved readability.Check these links for further details: