A java list of bytes 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#
import scala.collection.JavaConversions. _
object GfG
{
def main(args : Array[String])
{
val list = new java.util.ArrayList[Byte]()
list.add( 12 )
list.add( 124 )
list.add( 19 )
val stream = list.toStream
println(stream)
}
}
|
Example:2#
import scala.collection.JavaConversions. _
object GfG
{
def main(args : Array[String])
{
val list = new java.util.ArrayList[Byte]()
list.add(- 89 )
list.add(- 121 )
list.add(- 11 )
val stream = list.toStream
println(stream)
}
}
|
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
14 Jan, 2020
Like Article
Save Article