The most fundamental data type in Kotlin is the Primitive data type and all others are reference types like array and string. Java needs to use wrappers (java.lang.Integer) for primitive data types to behave like objects but Kotlin already has all data types as objects.
There are different data types in Kotlin:
Integer
These data types contain integer values.
Data Type | Bits | Min Value | Max Value |
---|
byte | 8 bits | -128 | 127 |
short | 16 bits | -32768 | 32767 |
int | 32 bits | -2147483648 | 2147483647 |
long | 64 bits | -9223372036854775808 | 9223372036854775807 |
Let's write a program to represent all the integer data types and their min and max values.
Example:
Kotlin
// Kotlin code
fun main(args : Array<String>) {
var myint = 35
// add suffix L for long integer
var mylong = 23L
println("My integer ${myint}")
println("My long integer ${mylong}")
var b1: Byte = Byte.MIN_VALUE
var