A string is a sequence of characters. In Scala, objects of String are immutable which means a constant and cannot be changed once created. when a new string is created by adding two strings is known as a concatenation of strings. Scala provides concat() method to concatenate two strings, this method returns a new string which is created using two strings. we can also use ‘+’ operator to concatenate two strings.
str1.concat(str2); Or "str1" + "str2";
Below is the example of concatenating two strings.
Using concat() method: This method appends argument to the string.
String 1:Welcome! GeeksforGeeks String 2: to Portal New String :Welcome! GeeksforGeeks to Portal This is the tutorial of Scala language on GFG portal
In above example, we are joining the second string to the end of the first string by using concat() function. string 1 is Welcome! GeeksforGeeks string 2 is to Portal. After concatenating two string we get new string Welcome! GeeksforGeeks to Portal.
Using + operator : we can add two string by using + operator.
After concatnate two string: Welcome toGeeksforGeeks
In above example, string 1 is Welcome to string 2 is GeeksforGeeks. By using + operator concatenating two string we get output After concatnate two string: Welcome toGeeksforGeeks.
- Scala Iterator concatenation with example
- Scala List concatenation with example
- Scala String
- Scala | String Interpolation
- Set in Scala | Set-2
- Scala Map
- Set in Scala | Set-1
- Scala | Either
- Operators in Scala
- How to get all the values from a Scala map
- Scala | Equals
- Scala | Product2
- Scala map contains() method with example
- Scala | Option
- Scala Map get() method with example
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.