w3resource

Scala Programming: Concatenate a given string to the end of another string


Write a Scala program to concatenate a given string to the end of another string.

Sample Solution:

Scala Code:

object Scala_String {

  def main(args: Array[String]): Unit = {
    val str1 = "Scala Exercises and ";
    val str2 = "Python Exercises";
    println("Original strings:")
    println("String 1: " + str1);
    println("String 2: " + str2);

    // Concatenate the two strings together.
    val str3 = str1.concat(str2);
    // Display the new String.
    println("The concatenated string: " + str3);
  }
}

Sample Output:

Original strings:
String 1: Scala Exercises and 
String 2: Python Exercises
The concatenated string: Scala Exercises and Python Exercises

Go to:


PREV : Write a Scala program to compare two strings lexicographically.
NEXT : Write a Scala program to test if a given string contains the specified sequence of char values.

Scala Code Editor :

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.