object Scala_Array {
import scala.collection.mutable.ArrayBuffer
def main(args: Array[String]): Unit = {
var array1 = Array("Python", "JAVA", "PHP", "C#", "C++", "SQL");
var array2 =
Array("MySQL", "SQL", "SQLite", "Oracle", "PostgreSQL", "DB2", "JAVA");
println("Array elements are : ")
for (c <- array1) {
print(s"${c}, ")
}
println("\nSecond array:")
for (c <- array2) {
print(s"${c}, ")
}
val temp: ArrayBuffer[String] = ArrayBuffer.empty[String]
for (i <- 0 to array1.length - 1) {
for (j <- 0 to array2.length - 1) {
if (array1(i).equals(array2(j))) {
temp.append(array1(i));
}
}
}
println("\nCommon elements of the said two arrays:")
for (c <- temp) {
print(s"${c}, ")
}
}
}
Sample Output:
Array elements are :
Python, JAVA, PHP, C#, C++, SQL,
Second array:
MySQL, SQL, SQLite, Oracle, PostgreSQL, DB2, JAVA,
Common elements of the said two arrays:
JAVA, SQL,
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer