Q:

Write a Scala program to remove a specific element from an given array

0

Write a Scala program to remove a specific element from an given array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_Array
{
  def main(args: Array[String]): Unit = 
 {
   val colors = Array("Red","Blue","Black","Green","White")
   println("Original Array elements:")
   // Print all the array elements
      for ( x <- colors ) {
         print(s"${x}, ")        
       }
     println("\nReplace some elements with ''/null etc.:")
      colors(0) = ""
      colors(3) = null
   println("Now the Original Array becomes:")
   // Print all the array elements
      for ( x <- colors ) {
         print(s"${x}, ")        
       }
  }
}

Sample Output:

Original Array elements:
Red, Blue, Black, Green, White, 
Replace some elements with ''/null etc.:
Now the Original Array becomes:
, Blue, Black, null, White,

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now