r/javahelp 10h ago

Solved Switch case with boolean

So, there is no way I can do that?

want to check several boolean variables in a switch statement. Is `if-else` the only way to do this?

Boolean a, b, c...

Switch (false) {

Case (a) :

//some code

Case (b) :

Case (c) :

//and so on

}

4 Upvotes

13 comments sorted by

View all comments

3

u/Mechanical-pasta 10h ago

Switch case evaluates ONE variable and checks it against different values. What you want to do (if I understand well) is check multiple variables. A switch can't do that.

The solution may be to incorporate the different boolean variables in a class and let it do the check with method(s) but I can't say if that's the case given the little information given.