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.
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
Excellent, thank you very much!
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.