0
0
Kotlinprogramming~10 mins

StringBuilder for performance in Kotlin - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a new StringBuilder instance.

Kotlin
val sb = [1]()
Drag options to blanks, or click blank then click option'
AString
BStringBuffer
CStringBuilder
DStringBuilderBuilder
Attempts:
3 left
💡 Hint
Common Mistakes
Using String instead of StringBuilder
Using a non-existent class like StringBuilderBuilder
2fill in blank
medium

Complete the code to append the word "Hello" to the StringBuilder.

Kotlin
sb.[1]("Hello")
Drag options to blanks, or click blank then click option'
Aappend
Badd
Cinsert
Dconcat
Attempts:
3 left
💡 Hint
Common Mistakes
Using add which does not exist
Using concat which is for Strings, not StringBuilder
3fill in blank
hard

Fix the error in the code to convert the StringBuilder content to a String.

Kotlin
val result = sb.[1]()
Drag options to blanks, or click blank then click option'
AtoString
BasString
CtoStr
Dstringify
Attempts:
3 left
💡 Hint
Common Mistakes
Using toStr which does not exist
Using stringify which is not a Kotlin method
4fill in blank
hard

Fill both blanks to build a string with numbers 1 to 3 separated by commas.

Kotlin
val sb = StringBuilder()
for (i in 1..3) {
    sb.[1](i)
    if (i [2] 3) sb.append(", ")
}
Drag options to blanks, or click blank then click option'
Aappend
B<
C>
Dinsert
Attempts:
3 left
💡 Hint
Common Mistakes
Using insert instead of append
Using > instead of < in the condition
5fill in blank
hard

Fill all three blanks to create a StringBuilder, append "Kotlin", and convert to String.

Kotlin
val [1] = [2]()
[1].append("Kotlin")
val result = [1].toString()
Drag options to blanks, or click blank then click option'
Abuilder
BStringBuilder
Csb
DStringBuffer
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'builder' as variable but not consistently
Using StringBuffer which is different