How to check whether a particular value exists in an array in Scala

Viewed 5998

I have a matrix in terms of a 2D array and another 1-D array. I am taking one element from the matrix and checking whether it exists in the array. Following is the code.

val array_intrval = Array.ofDim[Int](10)
var joint_matrix = Array.ofDim[Int][Int](5)(2)
for(i <- 0 to 4) {
  for (j <- 0 to 1) {
    var a = joint_matrix(i)(j)

After this, I want to check whether a exists in array_intrval, if not add a in array_intrval and then check whether there are some elements which is less than or equal to a. If yes, also put them in array_intrval. If a does exists in array_intrval, skip a and check for next element in joint_matrix.

I am a beginner in Scala and not able perform this. Any help regarding this will be highly appreciated.

1 Answers
Related