Kotlin Data Types

Kotlin Tutorial

Kotlin Data Types

Data types in Kotlin define what kind of data a variable can hold. Kotlin is a statically typed language, which means every variable has a specific data type.


1. Numbers (Numeric Data Types)

Integer Types

TypeSize
Byte8-bit
Short16-bit
Int32-bit
Long64-bit

Floating-Point Types

TypeSize
Float32-bit
Double64-bit

2. Boolean Data Type

Used for true or false values.


3. Character (Char)

Stores a single character.

  •  Use single quotes for Char.

4. String Data Type

Stores a sequence of characters.

Multi-Line String


5. Arrays

Used to store multiple values of the same type.

Access elements:


6. Nullable Data Types

By default, variables cannot be null.

To allow null:


7. Type Conversion

Kotlin does not allow implicit conversion.

Common conversions:

  • toInt()

  • toDouble()

  • toFloat()

  • toString()


8. Any, Unit, and Nothing

Any

Parent of all classes.

Unit

Represents no meaningful value (like void in Java).

Nothing

Represents no value at all (used in exceptions).


Summary

  • Kotlin has strongly typed data types

  • Supports nullable and non-nullable types

  • No implicit type casting

  • Rich standard data types

You may also like...