KtDevLog
  • Home
  • Kotlin Fundamentals
  • App Projects
  • Android Studio
  • Firebase
No Result
View All Result
KtDevLog
  • Home
  • Kotlin Fundamentals
  • App Projects
  • Android Studio
  • Firebase
No Result
View All Result
KtDevLog
No Result
View All Result
kotlin Data Types

kotlin Data Types

Md Sharif Mia by Md Sharif Mia
April 10, 2026
in Kotlin Fundamentals
Reading Time: 20 mins read
0
0
Share on FacebookShare on Twitter

Numbers

Kotlin provides several built-in types to represent numbers, categorized into integers and floating-point numbers. Unlike Java, there are no implicit widening conversions for numbers (e.g., you cannot assign an Int to a Long variable without an explicit conversion).

Kotlin
val inferedInt = 10 // Inferred as Int
val inferedLong = 10000000000 // Inferred as Long because it's too big for Int
val explicitLong = 10L // Explicitly defined as Long
KtDevlog

Integer Types

These types represent whole numbers without decimals.

TypeSize (bits)Min ValueMax ValueExample
Byte8-128127val b: Byte = 100
Short16-32,76832,767val s: Short = 30000
Int32-2³¹2³¹ – 1val i = 42 (Default for whole numbers)
Long64-2⁶³2⁶³ – 1

Floating-Point Types

These types represent numbers with decimal points. Kotlin adheres to the IEEE 754 standard for floating-point numbers.

Related Posts

Kotlin Control Flow: If, Else, and When expressions.

Kotlin Control Flow: If, Else, and When expressions.

April 10, 2026
Kotlin Variables val vs var

Kotlin Variables val vs var

April 10, 2026
Hello World with Kotlin

How to Write a Kotlin Hello World (A Beginner’s Guide)

April 11, 2026
TypeSize (bits)Significant BitsExample
Float3224 (approx. 6-7 decimal digits)val f = 3.14f (Note the ‘f’ or ‘F’ suffix)
Double6453 (approx. 15-16 decimal digits)val d = 3.14159 (Default for decimal numbers)

Booleans

The Boolean type represents logical values and has only two possible states: true and false. This type is fundamental for control flow structures like if statements and loops.

Kotlin
val isKotlinFun: Boolean = true
val isFishTasty = false // Type inference makes it a Boolean

if (isKotlinFun) {
    println("Yes, it is!")
}
KtDevlog

Characters

The Char type represents a single 16-bit Unicode character. Character literals are enclosed in single quotes, like 'A' or '1'.

Kotlin
val letter: Char = 'K'
val digit = '7' // Inferred as Char
// val notAChar = 'KO' // Error: too many characters
KtDevlog

Crucially, in Kotlin, Char is NOT a number type. You cannot directly assign a character to an integer variable (unlike in Java). You must use explicit conversion functions like .toInt() to get its ASCII/Unicode value.

Kotlin
val c = 'A'
// val i: Int = c // Error: Type mismatch
val code: Int = c.toInt() // Works, code will be 65
KtDevlog

Strings

The String type represents an immutable sequence of characters. String literals are enclosed in double quotes, like "Hello, KtDevLog!".

Kotlin
val greeting: String = "Welcome!"
val name = "Sharif" // Inferred as String
KtDevlog

Arrays

Arrays in Kotlin are represented by the Array class. They are invariant, meaning Array<String> is not a subtype of Array<Any>. You can create arrays using functions like arrayOf(), arrayOfNulls(), or the Array constructor.

Kotlin
val numbers = arrayOf(1, 2, 3, 4, 5) // Inferred as Array<Int>
val names: Array<String> = arrayOf("Sharif", "Mia", "KtDevLog")
KtDevlog

ShareTweetPin
Md Sharif Mia

Md Sharif Mia

Related Posts

Kotlin Control Flow: If, Else, and When expressions.
Kotlin Fundamentals

Kotlin Control Flow: If, Else, and When expressions.

April 10, 2026

If, Else statement Kotlinval age = 20 if (age >= 18) { println("Welcome to...

Kotlin Variables val vs var
Kotlin Fundamentals

Kotlin Variables val vs var

April 10, 2026

Val val name = "Sharif"val name = "Sharif" Use val for a variable whose value never...

Hello World with Kotlin
Kotlin Fundamentals

How to Write a Kotlin Hello World (A Beginner’s Guide)

April 11, 2026

Have you ever stared at a blank computer screen, wishing you knew how to...

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

  • About
  • FAQ
  • Contact
  • Advertise

© 2026 ktdevlog.

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In
No Result
View All Result
  • Home
  • Kotlin Fundamentals
  • App Projects
  • Android Studio
  • Firebase

© 2026 ktdevlog.