![]() |
In this article, we will learn how to check if a string is null in Scala. In Scala, you can check if a string is null using the following methods: Table of Content 1. Using the == operator:
Output: String is null 2. Using the eq method (recommended):The eq method is a null-safe way of comparing objects in Scala. It returns true if both operands are null, or if the operands point to the same object instance.
Output: String is null 3. Using Pattern Matching:
Output: String is null It’s generally recommended to use the eq method or pattern matching for checking null references, as they provide a more concise way of handling null values in Scala. |
Reffered: https://www.geeksforgeeks.org
Scala |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |