Kotlin - Basic Types

Kotlin Numbers

Kotlin does now not permit inward transformation of different insights types

There are following table records distinctive variable lengths for remarkable numbers.

Type Size
Float 32
Double 64
Long 64
Int 32
Short 16
Byte 8

For model, we will perceive how Kotlin works with various information types.


fun main(args: Array) { 

val an: Int = 100000 

val d: Double = 1000.00 

val f: Float = 10.00f 

val l: Long = 10000004 

val s: Short = 10 

val b: Byte = 1 

println("Your Int Value is "+a); 

println("Your Double Value is "+d); 

println("Your Float Value is "+f); 

println("Your Long Value is "+l); 

println("Your Short Value is "+s); 

println("Your Byte Value is "+b); 


it will produce the accompanying output


Int Value is 100000
Double Value is 1000.00
Float Value is 10.00
Long Value is 10000004
Short Value is 10
Byte Value is 1

Kotlin Characters

Kotlin speaks to character the utilization of char. Character should be pronounced in a solitary statement like 'c'.

Kotlin variable might be pronounced in strategies &#forty five; one the use of "var" and each other utilizing "val"


fun main(args: Array<String>) { 

val letter: Char //characterizing a variable  

letter = 'b' //Assigning an incentive to it  



The above bit of code will yield the accompanying yield in the program yield window.




Boolean is the articulation – either evident or false In the accompanying model, we will perceive how Kotlin deciphers Boolean.

fun main(args: Array<String>) { 

val letter: Boolean //characterizing a variable  

letter = false //Assinging an incentive to it  

println("Your character esteem is "+"$letter") 


output Your character esteem is false


Strings are man or lady clusters. Kotlin have string : uncooked String and got away String

fun main(args: Array) { 

var rawString :String = "I am Raw String!" 

val escapedString : String = "I am gotten away String!\n" 





Hello!I am avoided String! 

Hey!!I am Raw String!
Arrays Arrays are a set of homogeneous records.Kotlin helps arrays of various records types
fun main(args: Array<String>) {
   val numbers: IntArray = intArrayOf(1, 2, 3, 4, 5)
   println("Hey!! I am array WELOOKUPS"+numbers[2])

Hey!! I am array WELOOKUPS3


Gathering is an exceptionally basic a piece of the insights structure Kotlin has sorts of accumulation : immutable series and mutable collection immutable series: records, maps and units that can't be editable
mutable series gathering is editable.

fun main(args: Array<String>) { 

val numbers: MutableList<Int> = mutableListOf(1, 2, 3)/alterable List 

val readOnlyView: List<Int> = numbers/unchanging rundown 

println("my changeable rundown - "+numbers)/prints "[1, 2, 3]" 


println("my changeable rundown after expansion - "+numbers)/prints "[1, 2, 3, 4]" 


readOnlyView.clear()/⇒ does not aggregate 

/gives mistake 


variable rundown of accumulation.

main.kt:9:18: mistake: uncertain reference: clear 

readOnlyView.clear()/ - > does not arrange 


kotline have strategy are first(), last(), channel(), and so forth we have actualized Map and Set utilizing diverse implicit techniques.

fun main(args: Array<String>) { 

val things = listOf(1, 2, 3, 4) 

println("First Element of our rundown - "+items.first()) 

println("Last Element of our rundown - "+items.last()) 

println("Even Numbers of our List - "+items. 

channel { it % 2 = 0 })/returns [2, 4] 

val readWriteMap = hashMapOf("foo" to 1, "bar" to 2) 

println(readWriteMap["foo"])/prints "1" 

val strings = hashSetOf("a", "b", "c", "c") 

println("My Set Values are"+strings) 


The above bit of code yields the accompanying yield in the browser.


First Element of our rundown - 1 

Last Element of our rundown - 4 

Indeed, even Numbers of our List - [2, 4] 


My Set Values are[a, b, c] 


Ranges is another special normal for Kotlin



fun main(args: Array<String>) { 

val i:Int = 2 

for (j in 1..4) 

print(j)/prints "1234" 

on the off chance that (I in 1..10) {/likeness 1 > = I && I < = 10 

println("we found your number - "+i) 



above bit of code yields the accompanying yield in the program.

1234we found your number - 2