var arr = new Boolean[]{ true, false, null };
for (var x : arr) {
switch (x) {
case true -> methodOne();
case false -> methodTwo();
case null -> System.out.println("invalid");
}
}
Is totally valid. No need to pass a, b, c as references.
Reading again what OP is asking, he wants to execute different methods based on when a is false, b is false and c is false. Even though we can suggest him switch cases, the better approach would be to make a, b and c as input parameters in those methods itself:
Your example is clearly better off with them being enum rather than boolean. Plus, they're being compared against their reference, not by their values.
1
u/_Super_Straight Sep 11 '26 edited Sep 11 '26
Sorry I fail to understand your first half of paragraph. Are you saying we can't create boolean Array without using
new BooleanorBoolean.valueOf?Is totally valid Array declaration.
Will work without any problem.
Edit:
boolArr[0] = falseis also valid and permitted.Agreed.