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#
import scala.collection.JavaConversions. _
object GfG
{
def main(args : Array[String])
{
val list = new java.util.ArrayList[Float]()
list.add( 1.1 f)
list.add( 5.1 f)
list.add( 7.1 f)
val str = list.toString
println(str)
}
}
|
Example:2#
import scala.collection.JavaConversions. _
object GfG
{
def main(args : Array[String])
{
val list = new java.util.ArrayList[Float]()
list.add( 5.3 f)
list.add( 7.9 f)
list.add( 6.3 f)
val str = list.toString
println(str)
}
}
|
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...