Program to print Java Set of characters in Scala Last Updated : 29 Nov, 2019 Comments Improve Suggest changes Like Article Like Report 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 Set // of characters 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 of characters val set = new java.util.HashSet[Char]() // Adding characters to the Set set.add('a') set.add('b') set.add('c') // Displays output println(set) } // Assigning result method to set of characters val set = res } } Output: [a, b, c] Therefore, a set of characters 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 character elements to the stated set one after another and then prints the results. Example:2# Scala // Scala program to print Java Set // of characters 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 of characters val set = new java.util.HashSet[Char]() // Adding characters to the Set set.add('j') set.add('l') set.add('k') // Displays output println(set) } // Assigning result method to set val set = res } } Output: [j, k, l] It is same as above example but here one more element is added in the stated set of characters 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 in Scala N nidhi1352singh Follow Improve Article Tags : Scala Scala scala-collection Similar Reads Program to print Java List of characters in Scala A java list 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 Set in Scala 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 Scal 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 convert Java list of characters to Seq in Scala A java list of characters can be converted to sequence in Scala by utilizing toSeq method of Java in Scala. Here, we need to import Scalaâs JavaConversions object in order to make this conversions work else an error will occur. Now, lets see some examples and then discuss how it works in details. Ex 1 min read Program to convert Java Set of characters to Stream in Scala A java Set of characters can be converted to a Stream in Scala by utilizing toStream 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 1 min read Program to apply foreach() method on Java Set of characters in Scala The method foreach() can be applied on Java set of characters in Scala by utilizing Scala's JavaConversions object. Moreover, here we need to use JavaConversions object as foreach method is not there in Java language. Now, lets see some examples and then discuss how it works in details. Example:1# S 2 min read Like