Scala Stack clear() method with example
Last Updated :
03 Nov, 2019
In Scala Stack class
, the clear() method is utilized to delete all the elements of the stack.
Method Definition: def clear(): Unit
Return Type: It returns an empty queue.
Example #1:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( 1 , 2 , 3 , 4 , 5 )
println( "Before clear() method: " + s 1 )
val result = s 1 .clear
print( "After clear() method: " + result)
}
}
|
Output:
Before clear() method: Stack(1, 2, 3, 4, 5)
After clear() method: ()
Example #2:
import scala.collection.mutable. _
object GfG
{
def main(args : Array[String])
{
val s 1 = Stack( "geeks" , "for" , "geeks" )
println( "Before clear() method: " + s 1 )
val result = s 1 .clear
print( "After clear() method: " + result)
}
}
|
Output:
Before clear() method: Stack(geeks, for, geeks)
After clear() method: ()
Share your thoughts in the comments
Please Login to comment...