Scala Set tail() 方法示例
tail()方法用于返回一个集合,该集合由集合的第一个元素以外的所有元素组成。
Method Definition: def tail: Set[A]
Return Type: It returns a set consisting of all the elements except the first element of the set.
示例 #1:
// Scala program of tail()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(4, 1, 2, 3)
// Applying tail method
val result = s1.tail
// Display output
println(result)
}
}
输出:
Set(1, 2, 3)
示例 #2:
// Scala program of tail()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating a set
val s1 = Set(41, 12, 23, 43)
// Applying tail method
val result = s1.tail
// Display output
println(result)
}
}
输出:
Set(12, 23, 43)