A java Set of strings can be converted to a Traversable collection in Scala by utilizing toTraversable method of Java in Scala. Here, we need to import Scala’s JavaConversions object in order to make this conversions work.
Now, lets see some examples and then discuss how it works in details.
Set(i, am, good)
Here, the stated output is in same order as stated in the given set.
Set(am a, i, girl)
Here, the strings with more number of words are displayed first and strings of greater length are displayed at last.