How to check whether a value is a string in Scala

1 Answer

0 votes
val value: Any = "Scala"

if (value.isInstanceOf[String]) {
    println("The value is a string")
} else {
    println("The value is not a string")
}

  
  
/*
run:
    
The value is a string

*/

 



answered Jan 21, 2025 by avibootz
...