[Solved] Java replace if else with switch


For code like

if(a==1) {do1();}
else if(a==2) {do2();}
else if(a==3) {do2();}
else if(a==4) {do2();}
else { doOther(); }

Equal code will be

switch(a) {
    case 1: 
        do1();
        break;
    case 2: 
        do2();
        break;
    case 3: 
        do3();
        break;
    case 4: 
        do4();
        break;
    default:
        doOther();
        break;
 }

2

solved Java replace if else with switch