I like If's when you need to meet previous conditions and would like to handle what happens in the middle:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public void test(boolean a,boolean b,boolean c){ if (a){ statement; if(b){ statement; if(c){ statement; }else{ statement; } }else{ statement; } }else{ statement; } } |
Also, in really complicated algorithms you could use both:
1 2 3 4 5 6 7
| public void test(int a,boolean b,boolean c){ switch(a) { case 0: if(b && c){ statements } else { statements } break; case 1: if(b && !c){ statements } else { statements } break; case 2: if(!b && !c){ statements } else { statements } break; } } |
As far as I know, there are no performance gain or loss between either each of them, just use the one that fits best your situation and makes your code clearer.
BTW, off topic, I really hate the "break" command, so I try not to use switch

it has something to do with "go-to" in my head, so I hate it
tl;drBoth are just fine, they are tools to control the flow of the program, just use the one that fits you best
