Open In App

Program to convert Java list of doubles to a String in Scala

Last Updated : 14 Jan, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

A java list of doubles can be converted to a String in Scala by utilizing toString method of Java in Scala. Here, you 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 doubles in Java
val list = new java.util.ArrayList[Double]()
  
// Adding doubles to the list
list.add(1.34)
list.add(9.01)
list.add(7.1)
  
// Converting list to a String
val str = list.toString
  
// Displays output
println(str)
  
}
}


Output:

[1.34, 9.01, 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 doubles in Java
val list = new java.util.ArrayList[Double]()
  
// Adding doubles to the list
list.add(7.12)
list.add(6.12)
list.add(9.12)
  
// Converting list to a String
val str = list.toString
  
// Displays output
println(str)
  
}
}


Output:

[7.12, 6.12, 9.12]

Reference:
https://alvinalexander.com/scala/how-to-go-from-java-collections-convert-in-scala-interact.



Similar Reads

Program to convert Java list of doubles to Traversable in Scala
A java list of doubles can be converted to a Traversable collection in Scala by utilizing toTraversable method of Java in Scala. Here, you 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
1 min read
Program to convert Java list of doubles to a Vector in Scala
A java list of doubles can be converted to a Vector in Scala by utilizing toVector 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. Example:1# // Scala program to convert Java list //
1 min read
Program to convert Java list of doubles to an Iterable in Scala
A java list of doubles can be converted to an Iterable in Scala by utilizing toIterable method of Java in Scala. Here, you 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. Example:1# // Scala program to convert Java li
1 min read
Program to convert Java list of doubles to an Indexed Sequence in Scala
A java list of doubles can be converted to an Indexed Sequence in Scala by utilizing toIndexedSeq method of Java in Scala. Here, you 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. Example:1# // Scala program to conve
2 min read
Program to convert Java list of doubles to Seq in Scala
A java list of doubles 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. Example:1# // Scala program to convert Java list // to
1 min read
Program to convert Java list of doubles to Stream in Scala
A java list of doubles can be converted to 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 else an error will occur. Now, lets see some examples and then discuss how it works in details. Example:1# // Scala program to convert Java list // to
1 min read
Program to convert Java Set of doubles to a String in Scala
A java Set of doubles can be converted to a String in Scala by utilizing toString method of Java in Scala. Here, you 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 a String in Scala // Im
1 min read
Program to convert Java Set of doubles to a Traversable in Scala
A java Set of doubles can be converted to a Traversable collection in Scala by utilizing toTraversable method of Java in Scala. Here, you 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 a
1 min read
Program to convert Java set of doubles to a Vector in Scala
A java set of doubles can be converted to a Vector in Scala by utilizing toVector 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. Example:1# // Scala program to convert Java set // to
1 min read
Program to convert Java set of doubles to an Iterable in Scala
A java set of doubles can be converted to an Iterable in Scala by utilizing toIterable method of Java in Scala. Here, you 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. Example:1# // Scala program to convert Java set
1 min read