Hey there!
Welcome to ClearUrDoubt.com.
In this post, we will look at a Scala program to remove duplicates for an Array. We can achieve this by converting it to a Set object and then converting the set to array again.
Let’s look the program:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
package com.clearurdoubt object DuplicatesRemovalDemo { def main(args: Array[String]) { val array = Array(1,2,3,1,2,3,4) println("Before removing duplicates: " + array.mkString(",")) println("After removing duplicates: " + array.toSet.toArray.mkString(",")) } } |
Output:
Happy Learning.
Please leave a reply in case of any queries.