DEV Community

Yasha Gozwan Shuhada
Yasha Gozwan Shuhada

Posted on

Kotlin Basics

Image description

Data Types

// Type Annotation //
// String
val string: String = "Yasha Gozwan"

// Character
val char: Char = 'A'

// Integer Numbers
val byte: Byte = 122
val short: Short = 12_345
val int: Int = 1_234_567_891
val long: Long = 1_123_456_789_123_123_123L

// Float Numbers
val float: Float = 123.123F
val double: Double = 123.123

// Boolean
val isVerify: Boolean = false
val isSuccess: Boolean = true
Enter fullscreen mode Exit fullscreen mode

Strings

// String
val myStr = "Hello World"

// uppercase and lowercase
val upper = myStr.uppercase()
val lower = myStr.lowercase()

// Get length
// length
val myLength = myStr.length

// getting first and last character
val firstChar = myStr[0]
val lastChar = myStr[myStr.length - 1]
Enter fullscreen mode Exit fullscreen mode

String Interpolation

// String Interpolation
val name = "Yasha"
val age = 26
println("Hello everyone. My name is $name and i $age old thanks")
Enter fullscreen mode Exit fullscreen mode

Top comments (0)