Scala 2.11 added scala.collection.Searching
to the standard library. It uses binary search for indexed sequences and linear search otherwise.
import scala.collection.Searching._
Array(1, 2, 3, 4, 5).search(3)
Scala 2.11 added scala.collection.Searching
to the standard library. It uses binary search for indexed sequences and linear search otherwise.
import scala.collection.Searching._
Array(1, 2, 3, 4, 5).search(3)