Ivan Ivan - 3 months ago 30
Scala Question

How to check that an array contains a particular value in Scala 2.8?

I've got an array A of D unique (int, int) tuples.

I need to know if the array contains (X, Y) value.

Am I to implement a search algorithm myself or there is a standard function for this in Scala 2.8? I've looked at documentation but couldn't find anything of such there.

Answer

That seems easy (unless I'm missing something):

scala> val A = Array((1,2),(3,4))
A: Array[(Int, Int)] = Array((1,2), (3,4))

scala> A contains (1,2)
res0: Boolean = true

scala> A contains (5,6)
res1: Boolean = false

I think the api calls you're looking for is in ArrayLike.

Comments