A java Set can be converted to a List in Scala by utilizing toList 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.
List(GfG, is a, CS-portal)
Therefore, a list of string is returned. Here, firstly a set is created where, string elements are added to it utilizing add method. After that toList method is utilized in order to convert the stated set to the list of Strings.
List(nidhi, Author, is an)
It is same as above example but here the string with more words is displayed later than the strings with lesser one.
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.