Open In App

Scala List mkString() method with example

Last Updated : 13 Aug, 2019
Comments
Improve
Suggest changes
Like Article
Like
Report
The mkString() method is utilized to display all the elements of the list in a string.
Method Definition: def mkString: String Return Type: It returns all the elements of the list in a string.
Example #1: Scala
// Scala program of mkString()
// method

// Creating object
object GfG
{ 

    // Main method
    def main(args:Array[String])
    {
        // Creating a list
        val m1 = List(2, 3, 5, 7, 8)
        
        // Applying mkString method
        val result = m1.mkString
        
        // Displays output
        println(result)
        
    }
} 
 
Output:
23578
Example #2: Scala
// Scala program of mkString()
// method

// Creating object
object GfG
{ 

    // Main method
    def main(args:Array[String])
    {
        // Creating a list
        val m1 = List(2, 3, 5, 7, 5)
        
        // Applying mkString method
        val result = m1.mkString
        
        // Displays output
        println(result)
    
    }
} 
Output:
23575

Next Article

Similar Reads