Kotlin Data Types


Kotlin Data Types – Simplified & Fresh!

In Kotlin, every piece of data has a type — it tells Kotlin what kind of data you’re dealing with.

Kotlin usually figures out the type by looking at the value. But you can also declare it directly if needed.

Basic Examples

val number = 10           // Kotlin knows it's an Int
val price = 10.99         // This becomes a Double 
Val grade = 'A'           // A single character → Char 
val isActive = false      // Boolean type 
val greeting = "Hey!"     // Text → String 

You can also mention the type clearly like this:

val number: Int = 10 
val price: Double = 10.99 
val grade: Char = 'A' 
val isActive: Boolean = false 
Val greeting: String = "Hey!" 

Number Types

Kotlin splits numbers into two main families:

Whole Numbers (No Decimals)

Type Range Example
Byte -128 to 127 val a: Byte = 100
Short -32,768 to 32,767 val b: Short = 5000
Int -2B to +2B val c: Int = 100000
Long Massive values (ends with L) val d: Long = 15000000000L
If the value is huge, use Long.

Decimals (Numbers With Points)

Used when you need to deal with fractions or real-world values.

Type Precision Example
Float 6–7 digits val pi: Float = 3.14F
Double ~15 digits val value: Double = 9.999
Always add F to the end of a Float.

Scientific Notation

Yes, Kotlin supports scientific formats too!

val bigFloat: Float = 6E2F     // 600.0 
Val hugeDouble: Double = 1.2E4 // 12000.0 

Boolean Type

This type only knows two answers: yes or no.

val isOnline: Boolean = true 
Val isDarkMode: Boolean = false 
Great for decisions, conditions, and flags.

Character Type

This type stores a single letter or symbol. You must wrap it in single quotes.

val letter: Char = 'K' 
You can’t use numbers like 66 to represent letters — unlike Java, Kotlin doesn’t accept ASCII values.

Strings – Text Storage

A String holds words, sentences, or anything inside double quotes.

val message: String = "Welcome to Kotlin" 

A String is basically a bunch of characters put together.


Arrays – Storing Many Values

Arrays allow you to store several items in one variable.

val colors = arrayOf("Red", "Blue", "Green") 

Type Conversion – Changing Types

Kotlin doesn’t convert types automatically like Java. You need to manually convert values with special functions:

This is the correct way:

val count: Int = 5 
val bigCount: Long = count.toLong()  

Conversion Functions:

  • toByte()
  • toShort()
  • toInt()
  • toLong()
  • toFloat()
  • toDouble()
  • toChar()

Recap – Quick View

Type Group Types Purpose
Whole #s Byte, Short, Int, Long Counted values
Decimal #s Float, Double Prices, measurements
Text Char, String Characters & words
Logic Boolean True/False conditions
Multiple Array Group of items together

Prefer Learning by Watching?

Watch these YouTube tutorials to understand KOTLIN Tutorial visually:

What You'll Learn:
  • 📌 Kotlin Variables and Data Types. Kotlin Basic Syntaxes #3.2
  • 📌 Kotlin Tutorial for Beginners - Kotlin Data Types
Previous Next