dropRight()方法用於刪除隊列的最後“ n”個元素。
函數定義: def dropRight(n: Int): Queue[A]
返回類型: It returns a new queue that consists of all the elements except the last ‘n’ elements.
範例1:
// Scala program of dropRight()
// method
// Import Queue
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating queues
val q1 = Queue(1, 2, 3, 4, 5)
// Print the queue
println(q1)
// Applying dropRight method
val result = q1.dropRight(2)
// Displays output
print("Queue after dropRight(2) method: " + result)
}
}
輸出:
Queue(1, 2, 3, 4, 5) Queue after dropRight(2) method: Queue(1, 2, 3)
範例2:
// Scala program of dropRight()
// method
// Import Queue
import scala.collection.mutable._
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Creating queues
val q1 = Queue(1, 2, 3, 4, 5)
// Print the queue
println(q1)
// Applying dropRight method
val result = q1.dropRight(3)
// Displays output
print("Queue after dropRight(3) method: " + result)
}
}
輸出:
Queue(1, 2, 3, 4, 5) Queue after dropRight(3) method: Queue(1, 2)
相關用法
- Scala Set dropRight()用法及代碼示例
- Scala Map dropRight()用法及代碼示例
- Scala TreeSet dropRight()用法及代碼示例
- Scala List dropRight()用法及代碼示例
- Scala Stack dropRight()用法及代碼示例
- Scala SortedMap dropRight()用法及代碼示例
- Scala SortedSet dropRight()用法及代碼示例
- Scala Queue sum()用法及代碼示例
- Scala Queue +=:()用法及代碼示例
- Scala Queue last()用法及代碼示例
- Scala Queue take()用法及代碼示例
- Scala Queue min()用法及代碼示例
- Scala Queue ++()用法及代碼示例
- Scala Queue ++:()用法及代碼示例
- Scala Queue +=()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Scala Queue dropRight() method with example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。