dropRight()用於返回除最後一個'n'元素以外的所有元素。
函數定義: def dropRight(n: Int): Set[A]
返回類型: It returns a set containing all elements except last ‘n’ elements.
範例1:
// Scala program of dropRight()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating sets
val s1 = Set(1, 2, 3, 4, 5)
// Applying dropRight method
val s2 = s1.dropRight(1)
// Displays output
for(elem <- s2)
println(elem)
}
}
輸出:
5 1 2 3
範例2:
// Scala program of dropRight()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating sets
val s1 = Set(1, 2, 3, 4, 5)
// Applying dropRight method
val s2 = s1.dropRight(2)
// Displays output
for(elem <- s2)
println(elem)
}
}
輸出:
5 1 2
相關用法
- Scala Map dropRight()用法及代碼示例
- Scala SortedSet dropRight()用法及代碼示例
- Scala SortedMap dropRight()用法及代碼示例
- Scala Queue dropRight()用法及代碼示例
- Scala TreeSet dropRight()用法及代碼示例
- Scala List dropRight()用法及代碼示例
- Scala Stack dropRight()用法及代碼示例
- Scala Set max()用法及代碼示例
- Scala Map last()用法及代碼示例
- Scala Set last()用法及代碼示例
- Scala map()用法及代碼示例
- Scala Int to(end: Int)用法及代碼示例
- Scala Set map()用法及代碼示例
- Scala Map max()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Scala Set dropRight() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。