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

Number

There are total 6 types that comes under number.

Type Size (Bytes)
Byte 1
Short 2
Int 4
Long 8
Float 4
Double 8

Some Examples to support the same:

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.

Boolean

The Boolean type can have two values, either true or false.

String

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:

Char

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.

Array

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.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.