Given s : String , how can I do the result
s : String
s.first()
in a String ?
String
The string does not have a .first() function. Do you mean .head ?
.first()
.head
Using head and returning a string is as simple as:
head
s.head.toString
You can use the take method as follows:
take
scala> val s = "abcdef" s: String = abcdef scala> val first = s.take(1) first: String = a scala>
Another variant:
val s : String = "hello" val first : String = s(0)+""