Scala – Finding the index of an element in a list scala

listscala

How do I find the index of an element in a Scala list.

val ls = List("Mary", "had", "a", "little", "lamb")

I need to get 3 if I ask for the index of "little"

Best Answer

scala> List("Mary", "had", "a", "little", "lamb").indexOf("little")
res0: Int = 3

You might try reading the scaladoc for List next time. ;)