Skip to content
Gallery
Kotlin
Share
Explore
Kotlin Documenation

icon picker
Variables and Data Types

Kotlin has two types of variables: val and var.
val: Immutable variable. Once assigned, cannot be reassigned.
var: Mutable variable. Can be reassigned.

val name: String = "Kotlin" // name = "C#" (This is an error, can't be reassigned)
var age: Int = 10 // age = 12 (This is allowed)

// var or val init variable with out assigning the data is error
val userName: String // it's an error since there is no data assigned

Data Types

Kotlin is statically typed, meaning the type of a variable is known at compile time.
Integers
Unsigned integers
Floating-point numbers
Booleans
Characters
Strings
Examples:
val integer: Int = 10
val longNumber: Long = 100L
val doubleNumber: Double = 10.5
val floatNumber: Float = 10.5F
val booleanValue: Boolean = true
val charValue: Char = 'A'
val stringValue: String = "Hello"


Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.