toString()方法用於顯示Scala映射中的字符串。
函數定義: def toString(): String
返回類型: It returns a string from the stated map.
範例1:
// Scala program of toString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a map
val m1 = Map(3 -> "geeks", 4 -> "for", 4 -> "for")
// Applying toString method
val result = m1.toString
// Displays output
println(result)
}
}
輸出:
Map(3 -> geeks, 4 -> for)
範例2:
// Scala program of toString()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a map
val m1 = Map(3 -> "geeks", 4 -> "for", 2 -> "cs")
// Applying toString method
val result = m1.toString
// Displays output
println(result)
}
}
輸出:
Map(3 -> geeks, 4 -> for, 2 -> cs)
相關用法
- Scala Int toString()用法及代碼示例
- Scala Set toString()用法及代碼示例
- Scala Char toString()用法及代碼示例
- Scala String toString()用法及代碼示例
- Scala Queue toString()用法及代碼示例
- Scala SortedSet toString()用法及代碼示例
- Scala TreeSet toString()用法及代碼示例
- Scala Stack toString()用法及代碼示例
- Scala Float toString()用法及代碼示例
- Scala Iterator toString()用法及代碼示例
- Scala SortedMap toString()用法及代碼示例
- Scala Set max()用法及代碼示例
- Scala Int max()用法及代碼示例
- Scala Set sum()用法及代碼示例
注:本文由純淨天空篩選整理自nidhi1352singh大神的英文原創作品 Scala Map toString() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。