Skip to content
Related Articles

Related Articles

Scala Stack last() method with example
  • Last Updated : 03 Nov, 2019

In Scala Stack class, the isEmpty() is utilized to check if the stack is empty or not.

Method Definition: def isEmpty: Boolean

Return Type: It returns true if the stack is empty or else it returns false.

Example #1:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of isEmpty() 
// method 
  
// Import Stack 
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating stack
        val s1 = Stack(1, 3, 2, 7, 6, 5
          
        // Print the stack 
        println(s1
           
        // Applying isEmpty method  
        val result = s1.isEmpty
          
        // Display output 
        print("The stack is empty: " + result) 
         
    

chevron_right


Output:

Stack(1, 3, 2, 7, 6, 5)
The stack is empty: false

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// Scala program of isEmpty() 
// method 
  
// Import Stack 
import scala.collection.mutable._
  
// Creating object 
object GfG 
  
    // Main method 
    def main(args:Array[String]) 
    
      
        // Creating stack
        val s1 = Stack() 
          
        // Print the stack 
        println(s1
           
        // Applying isEmpty method  
        val result = s1.isEmpty
          
        // Display output 
        print("The stack is empty: " + result) 
         
    

chevron_right


Output:

Stack()
The stack is empty: true



My Personal Notes arrow_drop_up
Recommended Articles
Page :