Bird
0
0

Given this Kotlin function:

hard📝 Application Q9 of 15
Kotlin - Functions

Given this Kotlin function:

fun merge(vararg elements: String): String {
    return elements.joinToString("-")
}

What is the output of merge("x", "y", "z")?

A"xyz"
B"x-y-z"
C"x, y, z"
D"x y z"
Step-by-Step Solution
Solution:
  1. Step 1: Understand joinToString

    The function joins all strings with the separator "-".
  2. Step 2: Apply to inputs

    Joining "x", "y", "z" with "-" results in "x-y-z".
  3. Final Answer:

    "x-y-z" -> Option B
  4. Quick Check:

    joinToString with '-' separator produces 'x-y-z' [OK]
Quick Trick: joinToString uses given separator [OK]
Common Mistakes:
MISTAKES
  • Assuming default separator is comma
  • Ignoring separator argument
  • Confusing joinToString with concatenation

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes