Open In App

Scala Stack last() method with example

Last Updated : 03 Nov, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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:




// 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) 
         
    


Output:

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

Example #2:




// 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) 
         
    


Output:

Stack()
The stack is empty: true


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads