object Program {
def main(args: Array[String]): Unit = {
val animals = List(
"cat",
"bird",
"fish")
// Create a StringBuilder to store all list element values.
val builder1 = new StringBuilder()
// Call addString to add all strings with no separator.
animals.addString(builder1)
val result1 = builder1.toString()
println(result1)
// Use a separator with addString.
// ... Converts a list to a string.
val builder2 = new StringBuilder()
animals.addString(builder2,
"; ")
val result2 = builder2.toString()
println(result2)
}
}
catbirdfish
cat; bird; fish