String variable

A string is a well-structured set of characters, words, sentences, and paragraphs. String is a widely used data type in Kotlin. Unlike other variables, such as Integer, Float, or Boolean, which contain one specific type of value, Strings can contain a collection of different values and can store pretty much everything and anything.

Like other Kotlin data types, String variables can be declared with or without type inference, and everything within double quotes will be considered as a string:

var variable_name : String = "value in double quotes"
var message : String = "Hello"
var question : String = "What is your name?"

A string variable, message, is initialized with Hello, and another string variable, question, is assigned with What is your name?A string variable can be declared with the var or val keyword without stating the variable type, for example,  val name = "Bob":

fun main(args: Array<String>) {
var message : String = "Hello"
var question : String = "What is your name?"
println(question)
val name = "Bob"
var address = "Stockholm, Sweden"
println("My name is $name and i live in $address")
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.143.205.136