In Kotlin, everything is an object. While Kotlin often infers data types automatically, understanding the fundamental types is critical for writing robust applications.
Data types are divided into different groups:
Number types are divided into two groups:
123 or -456). Types include Byte, Short, Int, and Long.Float and Double.val myNum: Int = 5 // Int val myDoubleNum: Double = 5.99 // Double
The Boolean data type can only take the values true or false.
val isKotlinFun: Boolean = true val isFishTasty: Boolean = false
Char: Used to store a single character. A Char must be surrounded by single quotes, like 'A' or 'c'.String: Used to store a sequence of characters (text). A String must be surrounded by double quotes, like "Hello World".val myLetter: Char = 'D' val myText: String = "Hello"