带有示例的 Scala BitSet addString() 方法
Scala 位集是一组非负整数,它们表示为打包成 64 位字的可变大小的位数组。 addString() 方法用于将此可遍历或迭代器的所有元素附加到字符串构建器。
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)
val b = new StringBuilder()
// Applying BitSet addString() function
val bs1 = bitSet.addString(b)
// Displays output
println(bs1)
}
}
输出:
112233