Robert Munteanu Robert Munteanu - 1 year ago 74
Java Question

Multiple flags in one int value

I have a int variable which hold multiple flags, for instance:

int styles = ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED;

I can test the presence of a flag

boolean expanded = (styles & ExpandableComposite.EXPANDED) != 0;

How can I clear the value of a flag from
, i.e. dynamically remove
, without knowing the exact flags which are set in

dfa dfa
Answer Source

this is an old C idiom, still working in Java:

styles &= ~ExpandableComposite.EXPANDED;

However these days (>= Java 1.5) you should consider using:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download