Q:

Write a Scala program to check a given list is empty or not

0

Write a Scala program to check a given list is empty or not.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_List
{
def main(args: Array[String]): Unit = 
 {
   val nums = List(1, 3, 5, 2, 7, 9, 11, 5, 2, 14, 12, 3)
   println("Original list:")
   println(nums)   
   val result = nums.isEmpty
   println("Test the said list is empty or not?") 
   println(result)
   val nums1 = List()
   val result1 = nums1.isEmpty
   println("Test the said list is empty or not?") 
   println(result1)
  }
}

Sample Output:

Original list:
List(1, 3, 5, 2, 7, 9, 11, 5, 2, 14, 12, 3)
Test the said list is empty or not?
false
Test the said list is empty or not?
true

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now