- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to correctly concatenate strings in Kotlin?
There are different ways to concatenate strings in Kotlin. For example, we can use the $ operator or we can use the append() function or we can simply use the "+" operator to join two strings.
Example – Concatenate Using "$"
Kotlin provides an operator to reference a variable or expression. In this example, we will see how to concatenate two strings using the "$" operator.
fun main(args: Array<String>) { val a = "Tutorialspoint" val b = ".com" println("String 1: " + a) println("String 2: " + b) println("Concatenated String: " + "$a$b") }
Output
It will produce the following output −
String 1: Tutorialspoint String 2: .com Concatenated String: Tutorialspoint.com
Example – Concatenate Using append()
In this example, we will see how we can use String Builder object’s append() to concatenate two different strings into one. We will modify the above example in order to implement the same.
fun main(args: Array<String>) { val a = "Tutorialspoint" val b = ".com" println("String 1: " + a) println("String 2: " + b) println("Concatenated String: " + StringBuilder().append(a).append(b).toString()) }
Output
It will produce the following output −
String 1: Tutorialspoint String 2: .com Concatenated String: Tutorialspoint.com
Example – Concatenate Using "+"
We can simply use the "+" operator to concatenate strings. Let's modify the above example.
fun main(args: Array<String>) { val a = "Tutorialspoint" val b = ".com" println("String 1: " + a) println("String 2: " + b) println("Concatenated String: " + a+b) }
Output
It will produce the following output −
String 1: Tutorialspoint String 2: .com Concatenated String: Tutorialspoint.com
- Related Articles
- How to concatenate strings in R?
- How to concatenate several strings in JavaScript?
- How to concatenate two strings in C#?
- How to concatenate two strings in Python?
- How to concatenate two strings in Golang?
- How to concatenate two strings using Java?
- Concatenate strings in Arduino
- How do I concatenate strings in Swift?
- Different ways to concatenate Strings in Java
- Concatenate Multiple Strings in Java.
- Concatenate 2 strings in ABAP without using CONCATENATE function
- C++ Program to Concatenate Two Strings
- How to concatenate multiple C++ strings on one line?
- The Optimum Method to Concatenate Strings in Java.
- C++ program to concatenate strings in reverse order

Advertisements