Skip to content
Related Articles

Related Articles

Program to convert Java list of floats to a String in Scala
  • Last Updated : 14 Jan, 2020

A java list of floats can be converted to a String in Scala by utilizing toString 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 list
// to a String in Scala
  
// Importing Scala's JavaConversions object
import scala.collection.JavaConversions._
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating list of floats in Java
        val list = new java.util.ArrayList[Float]()
          
        // Adding floats to the list
        list.add(1.1f)
        list.add(5.1f)
        list.add(7.1f)
          
        // Converting list to a String
        val str = list.toString
          
        // Displays output
        println(str)
      
    }
}
Output:
[1.1, 5.1, 7.1]

Example:2#




// Scala program to convert Java list
// to a String in Scala
  
// Importing Scala's JavaConversions object
import scala.collection.JavaConversions._
  
// Creating object
object GfG
  
    // Main method
    def main(args:Array[String])
    {
      
        // Creating list of floats in Java
        val list = new java.util.ArrayList[Float]()
          
        // Adding characters to the list
        list.add(5.3f)
        list.add(7.9f)
        list.add(6.3f)
          
        // Converting list to a String
        val str = list.toString
          
        // Displays output
        println(str)
      
    }
}
Output:
[5.3, 7.9, 6.3]



My Personal Notes arrow_drop_up
Recommended Articles
Page :