Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Leer String Type | Core Data Types
Practice
Projects
Quizzes & Challenges
Quizzen
Challenges
/
Kotlin Data Types

bookString Type

Veeg om het menu te tonen

The String type in Kotlin is used to represent sequences of characters, such as words, sentences, or any other textual data. You use String variables to store and manipulate text. Declaring a String variable is straightforward: you specify the type String and assign it a value enclosed in double quotes. You can perform various operations on strings, including concatenation (joining strings together) and interpolation (inserting variable values directly into a string).

Main.kt

Main.kt

copy
1234567891011
package com.example fun main() { val firstName: String = "Alice" val lastName: String = "Smith" val fullName = firstName + " " + lastName val greeting = "Hello, $firstName!" println(fullName) println(greeting) }

In the code above, you see two common ways to combine and display text in Kotlin. Concatenation is performed using the + operator, as shown when creating the fullName variable by joining firstName, a space, and lastName. String interpolation uses the $ symbol to insert a variable's value directly into a string. In the greeting variable, $firstName is replaced with the value of the firstName variable, resulting in a personalized message. Both techniques allow you to build and work with dynamic text in your programs.

question mark

How do you insert a variable's value into a String in Kotlin?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 1. Hoofdstuk 4

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

Sectie 1. Hoofdstuk 4
some-alt