Program to convert Java Set of shorts to a String in Scala
Last Updated :
03 Jan, 2020
A java Set of shorts 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#
import scala.collection.JavaConversions. _
object GfG
{
def main(args : Array[String])
{
val set = new java.util.HashSet[Short]()
set.add( 1000 )
set.add(- 1000 )
set.add( 111 )
set.add(- 111 )
val str = set.toString
println(str)
}
}
|
Output:
[-1000, 1000, -111, 111]
Example:2#
import scala.collection.JavaConversions. _
object GfG
{
def main(args : Array[String])
{
val set = new java.util.HashSet[Short]()
set.add(- 1000 )
set.add( 1000 )
set.add(- 111 )
val str = set.toString
println(str)
}
}
|
Output:
[-1000, 1000, -111]
Share your thoughts in the comments
Please Login to comment...