Open In App
Related Articles

Program to convert Java Set of doubles to Sequence in Scala

Improve Article
Improve
Save Article
Save
Like Article
Like

A java Set of doubles 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 doubles in Java
        val set = new java.util.HashSet[Double]()
          
        // Adding doubles to the set
        set.add(3.2)
        set.add(51.2)
        set.add(63.2)
          
        // Converting set to Sequence 
        val seq = set.toSeq
          
        // Displays Sequence 
        println(seq)
      
    }
}

Output:

ArrayBuffer(3.2, 51.2, 63.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 doubles in Java
        val set = new java.util.HashSet[Double]()
          
        // Adding doubles to the set
        set.add(6.34)
        set.add(6.23)
        set.add(6.91)
          
        // Converting set to Sequence 
        val seq = set.toSeq
          
        // Displays Sequence 
        println(seq)
      
    }
}

Output:

ArrayBuffer(6.91, 6.23, 6.34)

Last Updated : 14 Jan, 2020
Like Article
Save Article
Similar Reads