WEB Button DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Kotlin - Basic Types


Kotlin Numbers

Kotlin does not allow internal conversion of different data 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.

In the following example, we will see how Kotlin works with different data 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  

println("$letter") 

} 

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

 

B 

Boolean

Boolean is the articulation either true 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

Strings are character arrays. Kotlin have string : uncooked String and got away String We have two kinds of string available in Kotlin - one is called raw String and another is called escaped String. Please enter the following code in our coding ground and see how Kotlin interprets the character variable.
 

fun main(args: Array) { 

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

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

println("Hello!"+escapedString) 

println("Hey!!"+rawString) 

} 

Output
 

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

Collections

Kotlin has two types of collection - one is immutable collection (which means lists, maps and sets that cannot be editable) and another is mutable collection (this type of collection is editable). It is very important to keep in mind the type of collection used in your application, as Kotlin system does not represent any specific difference in them.
 

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]" 

numbers.add(4) 

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

println(readOnlyView) 

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] 

1 

My Set Values are[a, b, c] 

Ranges

Ranges is another special normal for Kotlin Like Haskell, it provides an operator that helps you iterate through a range.

it is implemented using rangeTo() and its operator form is (..).

rangeTo()

 

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