0 votes
in Kotlin by
What are the Data Types in Kotlin?

1 Answer

0 votes
by

Data types are set of relatable values and describe the operations that can be operated on them. Similar to other programming languages, Kotlin also has its predefined set of data types like Int, Boolean, Char, Double, etc.

In Kotlin, every data type is considered as an object.

Now in this Kotlin basic Tutorial, let’s dive deeper into the predefined data types used in Kotlin.

Numbers :

Kotlin serves a set of built-in data types known as numbers, which are sub-categorize as Integers and Floating-Point Numbers.

Integers :

Integers are the category of numbers that has four types:

TypeSize (bits)Min valueMax value
Byte8-128127
Short16-3276832767
Int32-2,147,483,648 (-231)2,147,483,647 (231 – 1)
Long64-9,223,372,036,854,775,808 (-263)9,223,372,036,854,775,807 (263 – 1)

Floating Point Numbers :

Floating Point Numbers are the non-Integer numbers that carry some decimal values.

Float: Float is a 32- bit single-precision floating-point value.

Example: var: Float x = 3.25600

Double: Double is a 64- bit double – precision floating point value.

Example: var: Double y = 2456.345587

Booleans :

Booleans data type in Kotlin is significant to represent the logical values. There are only two possible values in Boolean that is either true or false.

For Example: val day = true

Val day2 = false

Character :

Characters in Kotlin are represented with the help of the keyword called char. In Kotlin, single quotes represent the declaration of char. In java, char are sometimes used as numbers that is not possible in kotlin.

For Example:

val onechar = 'x'
print(onechar) //  output : x
Val onedigit = '7'
print(onedigit) // output : 7

Related questions

0 votes
0 votes
asked May 26, 2022 in Kotlin by Robin
0 votes
asked May 26, 2022 in Kotlin by Robin
0 votes
asked May 26, 2022 in Kotlin by Robin
...