带有分隔符的 Scala BitSet addString(b: StringBuilder, sep: String) 方法
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 addString(sb: mutable.StringBuilder, start: String, sep: String, end: String)
方法用于使用分隔符字符串将此位集的所有元素附加到字符串构建器。
Method Definition: def addString()
Return Type: It returns the string builder b to which elements were appended.
示例 #1:
// Scala program of Bitset addString
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val bitSet: BitSet = BitSet(11, 22, 33, 44)
val b = new StringBuilder()
// Applying BitSet addString() function
val bs1 = bitSet.addString(b, ", ")
// Displays output
println(bs1)
}
}
输出:
11, 22, 33, 44
示例 #2:
// Scala program of Bitset addString
// method
import scala.collection.immutable.BitSet
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
val bitSet: BitSet = BitSet(1, 2, 3)
val b = new StringBuilder()
// Applying BitSet addString() function
val bs1 = bitSet.addString(b, "-Geek- ")
// Displays output
println(bs1)
}
}
输出:
1-Geek- 2-Geek- 3