Q:

Write a Scala program to remove duplicate elements from an array of strings

0

Write a Scala program to remove duplicate elements from an array of strings.

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 = {     
       var my_array = Array("bcd", "abd", "jude", "bcd", "oiu", "gzw", "oiu");
       println("Orginal array:")
       for ( x <- my_array) {
         print(s"${x}, ")        
        }      

        var f =0
        for (i <- 0 to my_array.length-1)
         {
           var x = f+1;
           for (j <- x to my_array.length-1)
            {
                if(my_array(f) == my_array(x) && (f != x) )
                {
                    println("\nDuplicate Element: "+my_array(x));
                }
              x=x+1;
            }
           f=f+1;
        }
       }
}

Sample Output:

Orginal array:
bcd, abd, jude, bcd, oiu, gzw, oiu, 
Duplicate Element: bcd
Duplicate Element: oiu

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