带有示例的 Scala BitSet addString(sb: mutable.StringBuilder, start, sep, end) 方法
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 addString(sb: mutable.StringBuilder, start: String, sep: String, end: String)
方法用于使用 start、end 和 separator 字符串将此 bitset 的所有元素附加到字符串构建器。
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(0, 1, 2, 3)
val b = new StringBuilder()
// Applying BitSet addString() function
val bs1 = bitSet.addString(b)
// Displays output
println(bs1)
}
}
输出:
0123
示例 #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(11, 22, 33, 44)
val b = new StringBuilder()
// Applying BitSet addString() function
val bs1 = bitSet.addString(b, "BitSet(", ", ", ")")
// Displays output
println(bs1)
}
}
输出:
BitSet(11, 22, 33, 44)