Program to print Java Set in Scala Last Updated : 25 Nov, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report A java Set can be returned from a Scala program by writing a user defined method of Java in Scala. Here, we don't even need to import any Scala’s JavaConversions object in order to make this conversions work. Now, lets see some examples. Example:1# Scala // Scala program to print Java Set // in Scala // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a java method in Scala def res = { // Creating a java Set val set = new java.util.HashSet[Int]() // Adding elements to the Set set.add(6) set.add(5) // Displays output println(set) } // Assigning result method to set val set = res } } Output: [5, 6] Therefore, a set is returned from a Java method. Here, we don't need to import any object of Scala. In the above program a Java method is written in Scala program. Where, this method adds the elements of the Set to the stated set one after another and then prints the results. Example:2# Scala // Scala program to print Java Set // in Scala // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating a java method in Scala def res = { // Creating a java Set val set = new java.util.HashSet[Int]() // Adding elements to the Set set.add(6) set.add(5) set.add(2) // Displays output println(set) } // Assigning result method to set val set = res } } Output: [2, 5, 6] It is same as above example but here one more element is added in the stated set and as it is a set so, the order of the elements is maintained. Comment More infoAdvertise with us Next Article Program to print Java Set of characters in Scala N nidhi1352singh Follow Improve Article Tags : Scala Scala scala-collection Similar Reads Program to print Java List in Scala A java list can be returned from a Scala program by writing a user defined method of Java in Scala. Here, we don't even need to import any Scalaâs JavaConversions object in order to make this conversions work. Now, lets see some examples. Example:1# Scala // Scala program to print Java List // in Sc 2 min read Program to print Java Set of Strings in Scala A java Set of strings can be returned from a Scala program by writing a user defined method of Java in Scala. Here, we don't even need to import any Scalaâs JavaConversions object in order to make this conversions work. Now, lets see some examples. Example:1# Scala // Scala program to print Java Set 2 min read Program to print Java Set of characters in Scala A java Set of characters can be returned from a Scala program by writing a user defined method of Java in Scala. Here, we don't even need to import any Scalaâs JavaConversions object in order to make this conversions work. Now, lets see some examples. Example:1# Scala // Scala program to print Java 2 min read Program to print Java List of Strings in Scala A java list of strings can be returned from a Scala program by writing a user defined method of Java in Scala. Here, you don't even need to import any Scalaâs JavaConversions object in order to make this conversions work. Now, lets see some examples. Example:1# Scala // Scala program to print Java L 2 min read Program to convert Java Set to List in Scala 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. Example:1# Scala // Scala program to conver 2 min read Program to convert Java list to Set in Scala A java list can be converted to Set in Scala by utilizing toSet 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. Example:1# Scala // Scala program to convert J 2 min read Like