Scala List mkString() method with a start, a separator and an end with example
This method is same as mkString() method but here a start, a separator and an end is also included.
Method Definition: defmkString(start: String, sep: String, end: String): String
Return Type: It returns the elements of the list as a string along with a stated start, separator and an end.
Let’s check some examples.
Example #1:
// Scala program of mkString() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a list val m 1 = List( 2 , 3 , 5 , 7 , 8 ) // Applying mkString method val result = m 1 .mkString( "_" , "*" , "_" ) // Displays output println(result) } } |
Output:
_2*3*5*7*8_
Example #2:
// Scala program of mkString() // method // Creating object object GfG { // Main method def main(args : Array[String]) { // Creating a list val m 1 = List( 2 , 3 , 5 , 7 , 5 ) // Applying mkString method val result = m 1 .mkString( "/" , "_" , "/" ) // Displays output println(result) } } |
Output:
/2_3_5_7_5/
Please Login to comment...