Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте String Type | Core Data Types
Practice
Projects
Quizzes & Challenges
Вікторини
Challenges
/
Kotlin Data Types

bookString Type

Свайпніть щоб показати меню

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

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 4

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 4
some-alt