Labs ICT
โญ Pro Login

Data Types

Kotlin has all the standard data types you'd expect, plus some nice touches that make working with them smooth.

Numbers

Kotlin gives you these number types out of the box:

  • Int โ€” whole numbers like 42, -10, 0
  • Long โ€” bigger whole numbers, suffix with L: 42L
  • Float โ€” decimal numbers with single precision, suffix with f: 3.14f
  • Double โ€” decimal numbers with double precision: 3.14159
  • Short โ€” small whole numbers (-32768 to 32767)
  • Byte โ€” tiny numbers (-128 to 127)

fun main() {
  val age: Int = 25
  val population: Long = 8_000_000_000L
  val price: Float = 19.99f
  val pi: Double = 3.1415926535
  println(age)
  println(population)
  println(price)
  println(pi)
}
    

See the underscores in 8_000_000_000? That's valid Kotlin โ€” it makes large numbers readable.

Boolean

Good old true and false.


fun main() {
  val isKotlinFun: Boolean = true
  println("Is Kotlin fun? $isKotlinFun")
}
    

Char and String

Char is a single character in single quotes. String is text in double quotes.


fun main() {
  val letter: Char = 'K'
  val message: String = "Kotlin is cool"
  println(letter)
  println(message.uppercase())
}
    
Try it Yourself โ†’

๐Ÿงช Quick Quiz

Which Kotlin type represents a whole number?