Kotlin Basic Types

Here you will learn about kotlin basic types.

Data types are fundamental when it comes to any programming language, basically it tells the compiler the type of data it should expect in the defined variable.

It can be a string, bool, integer, float, double, char and many more. Lets discuss them one by one in detail.

Kotlin Basic Types


There are total 6 types that comes under number.

Some Examples to support the same:

val someInt = 553  //Integer
val someLong = 43L  //Long
val someFloat = 314.43F  //Float
val someDouble = 425.78  //Double
val someHexadecimal = 0x4F //Hexadecimal
val someBinary = 01010101 //Binary (Base 2)
val someByte: Byte = 10  //Byte

In kotlin we don’t have to explicitly mention the type of a variable. Still if you want you can mention in following way.

You can learn more about variables here.
val someInt: Int = 553


The Boolean type can have two values, either true or false.
val someTrueBoolean = true
val someFalseBoolean = false 

val a = 1
val b = 2
val find = a < b // variable find will contain true


Strings in kotlin are as simple as it sounds.

It is must to surround it via double quotes or a multiline string can be declared as shown below:


The data type char, stores a single letter, number or a symbol.

Char is conceptually a fixed length, blank padded string.

Any trailing spaces is removed on input, and only restores on output.

The default length is 1.

The size of character variable is 1 byte.


Arrays are defined by the arrayOf() operator: We can also define array that contain specific type of values using utility functions such as charArrayOf(), booleanArrayOf(), longArrayOf(), shortArrayOf(), byteArrayOf() and this can be done for all primitive datatypes.

We will discuss more about array in our later tutorials.

Comment down below if you have any queries related to kotlin basic types.


Post a Comment

Kotlin Guide © 2013. All Rights Reserved. Powered by Blogger