Hi guys,

I am using boolean variables as flags in a program and i want to be able to invert the value.

for example if the current value is true, then it must be changed to false; doesn't matter if i don't know what the current value is.

Hi guys,

I am using boolean variables as flags in a program and i want to be able to invert the value.

for example if the current value is true, then it must be changed to false; doesn't matter if i don't know what the current value is.

Use the ! operator.

boolean a = true;
        System.out.println (Boolean.toString(a)); // true
        a = !a;
        System.out.println (Boolean.toString(a)); // false
commented: Yes! +8
commented: A no nonsense answer in like 1 minute +2

Excellent, thank you very much!