此方法與 addString() 方法相同,但此處還包含分隔符。
Method Definition: def addString(b:StringBuilder, sep:String):StringBuilder
Where, sep is the separator stated.
Return Type: It returns the elements of the SortedMap in the String Builder and a separator is also added between the elements of the SortedMap.
範例1:
// Scala program of addString()
// method with a separator
import scala.collection.SortedMap
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedMap
val m1 = SortedMap("geeks" -> 5, "for" -> 3, "cs" -> 2)
// Applying addString method
// and a separator
val result = m1.addString(new StringBuilder(), "_")
// Displays output
println(result)
}
}
輸出:
cs -> 2_for -> 3_geeks -> 5
範例2:
// Scala program of addString()
// method with a separator
import scala.collection.SortedMap
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a SortedMap
val m1 = SortedMap("geeks" -> 5, "for" -> 3, "geeks" -> 2)
// Applying addString method
// and a separator
val result = m1.addString(new StringBuilder(), "_")
// Displays output
println(result)
}
}
輸出:
for -> 3_geeks -> 2
因此,這裏刪除了相同的鍵。
相關用法
- Scala SortedMap addString()用法及代碼示例
- Scala SortedMap addString()用法及代碼示例
- Scala Mutable SortedMap addString()用法及代碼示例
- Scala Mutable SortedMap mkString()用法及代碼示例
- Scala Iterator addString()用法及代碼示例
- Scala Map addString()用法及代碼示例
- Scala Map addString()用法及代碼示例
- Scala Iterator addString()用法及代碼示例
- Scala List addString()用法及代碼示例
- Scala List addString()用法及代碼示例
- Scala SortedMap addString()用法及代碼示例
- Scala SortedMap mkString()用法及代碼示例
- Scala SortedMap mkString()用法及代碼示例
- Scala Mutable SortedMap toArray()用法及代碼示例
- Scala Mutable SortedMap toSeq()用法及代碼示例
- Scala Mutable SortedMap toString()用法及代碼示例
- Scala Mutable SortedMap toList()用法及代碼示例
- Scala Mutable SortedMap takeRight()用法及代碼示例
- Scala Mutable SortedMap take()用法及代碼示例
- Scala Mutable SortedMap tail()用法及代碼示例
- Scala Mutable SortedMap transform()用法及代碼示例
注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Scala Mutable SortedMap addString() method with a separator with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。