A java Set of floats can be converted to a 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.
Now, lets see some examples and then discuss how it works in details.
Example:1#
// Scala program to convert Java set // to Sequence in Scala // Importing Scala's JavaConversions object import scala.collection.JavaConversions._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating set of floats in Java val set = new java.util.HashSet[Float]() // Adding floats to the set set.add(1.2f) set.add(3.2f) set.add(8.2f) // Converting set to Sequence val seq = set.toSeq // Displays Sequence println(seq) } } |
chevron_right
filter_none
Output:
ArrayBuffer(8.2, 3.2, 1.2)
Example:2#
// Scala program to convert Java set // to Sequence in Scala // Importing Scala's JavaConversions object import scala.collection.JavaConversions._ // Creating object object GfG { // Main method def main(args:Array[String]) { // Creating set of floats in Java val set = new java.util.HashSet[Float]() // Adding floats to the set set.add(2.4f) set.add(2.6f) set.add(2.1f) // Converting set to Sequence val seq = set.toSeq // Displays Sequence println(seq) } } |
chevron_right
filter_none
Output:
ArrayBuffer(2.6, 2.1, 2.4)
Recommended Posts:
- Program to convert Java set of floats to an Indexed Sequence in Scala
- Program to convert Java list of floats to an Indexed Sequence in Scala
- Program to convert Java Set of floats to a String in Scala
- Program to convert Java Set of floats to a Traversable in Scala
- Program to convert Java set of floats to a Vector in Scala
- Program to convert Java set of floats to an Iterable in Scala
- Program to convert Java Set of floats to Stream in Scala
- Program to convert Java list of floats to a String in Scala
- Program to convert Java list of floats to Traversable in Scala
- Program to convert Java list of floats to a Vector in Scala
- Program to convert Java list of floats to an Iterable in Scala
- Program to convert Java list of floats to Seq in Scala
- Program to convert Java list of floats to Stream in Scala
- Program to convert Java set of Shorts to an Indexed Sequence in Scala
- Program to convert Java Set to Sequence in Scala
- Program to convert Java set of integers to an Indexed Sequence in Scala
- Program to convert Java set of characters to an Indexed Sequence in Scala
- Program to convert Java set of Strings to an Indexed Sequence in Scala
- Program to convert Java set of doubles to an Indexed Sequence in Scala
- Program to convert Java set of bytes to an Indexed Sequence in Scala
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

