What is the equivalent of !boolean (negative) on Kotlin

Issue

I have recently decided to switch from Java to Kotlin for Android Development. I don’t know what to Google, so I’m asking here.

If we want to get the opposite of a boolean, we put a ! before it. Eg: I want the inside code to run only if the contains() returns false. How to do that?

Example, we do this in Java:

if (!string_text.contains(" "))

How do I write this in Kotlin?

Solution

! is the boolean not operator, same as Java.

Check https://kotlinlang.org/docs/reference/keyword-reference.html#operators-and-special-symbols

Answered By – al3c

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published