I am trying achieve the below in scala
var date="12/01/2021"
var a,b,c = date.split("/")
print(a,b,c)
//expected result
12,01,2021
There's no way you know for sure the size of the array after splitting, which is why you cannot destructure it like this.
However you can use pattern matching:
date.split("/") match {
case Array(a, b, c) => print(...)
case _ => print("invalid format")
}
Or just access the array by index (not safe):
val arr = date.split("/")
val (a, b, c) = (arr(0), arr(1), arr(2))