Kotlin Data Types

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
| Type | Size |
|---|---|
Byte | 8-bit |
Short | 16-bit |
Int | 32-bit |
Long | 64-bit |
Floating-Point Types
| Type | Size |
|---|---|
Float | 32-bit |
Double | 64-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
