Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

scala
communitycreator

What is the list.isEmpty method in Scala?

Harris Amjad

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The list.isEmpty function in Scala checks if a list is empty. The list.isEmpty function returns true if the list is empty; otherwise, it returns false.

The illustration below shows a visual representation of the list.isEmpty function.

Visual representation of the list.isEmpty function

Syntax

list_name.isEmpty

list_name is the name of the list.

Parameters

The list.isEmpty function does not require any parameters.

Return value

If the list is empty, the list.isEmpty function returns true; otherwise, it returns false.

Code

The following code shows how to use the list.isEmpty function in Scala.

import scala.collection.mutable.Map
object Main extends App {
  //filled list
  var list_1 = List(1,3,4,2,0)

  //list_1 elements 
  println("The list_1 elements: " + list_1);
  println("The list_1 is empty: " + list_1.isEmpty);

  //empty list
  var list_2 = List()
  //list_2 elements 
  println("The list_2 elements: " + list_2);
  println("The list_2 is empty: " + list_2.isEmpty);

}

RELATED TAGS

scala
communitycreator

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring