Booleans

Booleans are used to represent a value which is either true or false as you would expect. Booleans belong to type Boolean.
On the JVM, non-nullable values of this type are represented as values of the primitive type boolean.
Boolean is defined in package Kotlin. It has the following method definition:
METHOD DEFINITION

public final class Boolean : Comparable<Boolean>

Normally it has only two values : true and false.

var old=true
var young=false

EXAMPLE

fun main(args: Array<String>) {
    var old=true
    var young=false
    println(old == young)
}

RESULT

false

Booleans are boxed suppose a nullable reference is needed.
Built in operations for a boolean can include:

  • || – lazy disjunction
  • && – lazy conjunction
  • ! - negation

EXAMPLE - Negation

fun main(args: Array<String>) {
    var z='z'
    var a='a'
    println(a != z)
}

EXAMPLE

true

EXAMPLE - Lazy conjunction

fun main(args: Array<String>) {
    val old=true
    val young=false
    val a='a'
    val z='z'

    println(old != young && a == z)
}

RESULTS

false

EXAMPLE - Lazy disjunction

fun main(args: Array<String>) {
    val old=true
    val young=false
    val a='a'
    val z='z'

    println(old != young || a == z)
}

RESULT

true