What does an exclamation mark mean in Java?

Yes it does mean the logical opposite. It works even with equals operator.

Assuming your method return a basic bool type

// means the Network is NOT connected
if (!NetworkConnected()) 

This is equivalent to

if (NetworkConnected() != true) 

So logically means

if (NetworkConnected() == false) 

Now assuming you method return a Boolean (indeed a real object), this means

// means the Network is NOT connected
if (! Boolean.TRUE.equals(NetworkConnected());

or

if (Boolean.FALSE.equals(NetworkConnected());

Leave a Comment