How in Scala to find unique items in List?
Scala List distinct() method with example. The distinct() method is utilized to delete the duplicate elements from the stated list. Return Type: It returns a new list of elements without any duplicates.
List<int> myList = list. Distinct(). ToList();
contains() function in Scala is used to check if a list contains the specific element sent as a parameter. list. contains() returns true if the list contains that element.
Solution. The distinct method returns a new collection with the duplicate values removed. Remember to assign the result to a new variable. This is required for both immutable and mutable collections.
In 2.8, it's:
List(1,2,3,2,1).distinct // => List(1, 2, 3)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With