You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description: 'Strings are immutable objects that are sequences of characters contained within a pair of double quotes.'
4
+
Subjects:
5
+
- 'Computer Science'
6
+
Tags:
7
+
- 'Strings'
8
+
- 'Data Types'
9
+
- 'Characters'
10
+
CatalogContent:
11
+
- 'learn-kotlin'
12
+
- 'paths/computer-science'
13
+
---
14
+
15
+
**Strings** are immutable objects that represent a sequence of characters contained within double quotes (`""`).
16
+
17
+
## Syntax
18
+
19
+
```pseudo
20
+
val stringName: String = "string value"
21
+
```
22
+
23
+
In Kotlin, string values are always defined as instances of the `String` class.
24
+
25
+
### String Templates
26
+
27
+
Templates can also be used to dynamically produce string values. Dynamic values don't have to start as strings, and can either be directly referenced with a dollar sign (`$`) or evaluated as a string with additional curly braces (`{}`).
28
+
29
+
## Example
30
+
31
+
The following example showcases the various ways strings are used in Kotlin:
32
+
33
+
```kotlin
34
+
funmain(args:Array<String>) {
35
+
// String literals
36
+
val greeting:String="Hello, World!"
37
+
println(greeting)
38
+
39
+
// String templates
40
+
val dynamicValue =4
41
+
val stringOne:String="The value of dynamicValue is $dynamicValue"
42
+
System.out.println(stringOne)
43
+
44
+
val a = dynamicValue
45
+
val b =5
46
+
val stringTwo:String="The sum of a and b is ${a + b}"
0 commit comments