The foreach() method is utilized to apply the given function to all the elements of the SortedMap.
Method Definition: def foreach(f: ((A, B)) => Unit): Unit
Return Type: It returns all the elements of the SortedMap after applying the given function to each of them.
key=1, value=for key=2, value=cs key=3, value=geeks key=6, value=geeks
key=1, value=for key=2, value=cs key=3, value=geeks
So, the identical elements are taken only once.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.