Bird
0
0

Which of the following is the correct way to concatenate two Strings str1 and str2 in Kotlin?

easy📝 Syntax Q12 of 15
Kotlin - Data Types
Which of the following is the correct way to concatenate two Strings str1 and str2 in Kotlin?
Astr1 & str2
Bstr1 + str2
Cstr1.join(str2)
Dstr1.append(str2)
Step-by-Step Solution
Solution:
  1. Step 1: Recall Kotlin String concatenation syntax

    Kotlin uses the + operator to join two Strings.
  2. Step 2: Check each option

    Only str1 + str2 is valid Kotlin syntax for concatenation.
  3. Final Answer:

    str1 + str2 -> Option B
  4. Quick Check:

    Use + to join Strings [OK]
Quick Trick: Use + to combine Strings, like adding words together [OK]
Common Mistakes:
MISTAKES
  • Using methods like append or join which don't exist on Kotlin String
  • Using & which is not a Kotlin operator for Strings
  • Trying to modify Strings directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Kotlin Quizzes