This example shows a simple Kotlin string example. Strings are a sequence of characters. For example, "Hello there!" is a string literal.
In Kotlin, all strings are objects of String class. Meaning, string literals such as "Hello there!" are implemented as instances of this class.
In Kotlin, all strings are objects of String class. Meaning, string literals such as "Hello there!" are implemented as instances of this class.
Kotlin String Example
The example creates a string, uses a string concatenation operation, and determines the width of the string.
package net.javaguides.kotlin.examples
fun main(args: Array<String>) {
 
 val s = "Source Code Examples"
 println(s)
 println("sourcecodeexamples" + ".net")
 println("The string has " + s.length + " characters")
}
Output:
Source Code Examples
sourcecodeexamples .net
The string has 20 charactersval s = "Source Code Examples" println(s)In Kotlin, strings are concatenated with the + operator:
println("sourcecodeexamples" + ".net")
Comments
Post a Comment