Scala - addString() method with a start, a separator and an end Code Example

The code for addString() method with a start, a separator and an end

import scala.collection.immutable.SortedMap

// Creating object
object GfG {
  // The main() method
  def main(args: Array[String]) {
    // Creating a SortedMap
    val sMap = SortedMap("Hello!" -> 6, "Bye" -> 3, "Bye" -> 3)

    // Using addString() method 
    val result = sMap.addString(new StringBuilder(), ">>>", "|", "--")

    // Printing result
    println(result)
  }
}

/*
Output:
>>>Bye -> 3|Hello! -> 6--

Note: The identical keys are removed.
*/
Code by IncludeHelp, on August 8, 2022 04:11

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.