Program to convert Java List of floats to an Indexed Sequence in Scala

Here, we will see how to convert Java List of Floats to an Indexed Sequence in Scala?
Submitted by Shivang Yadav, on October 30, 2020

Scala programming language is based on Java that enables it to be interoperable with java. As Scala code is compiled to bytecode which is the same as compiled by java.

List of Floats in Java

It is simply, a list in java that contains elements of float data type.

Syntax to create a list of float in java,

List<float> floatList = new ArrayList<float>()

Syntax to create a list of float in Scala,

val floatList = new java.util.ArrayList[Float]()

Indexed Sequence

It is a subtrait of the trait sequence that returns a vector which allows random and fast access to the elements.

Program to convert java list of floats to an Indxed Sequence in Scala

// Program to illustrate the conversion of java list 
// of floats to an indexed sequence in scala

import scala.collection.JavaConversions._

object myObject {  
    def main(args:Array[String]) { 
        val floatList = new java.util.ArrayList[Float]() 
        val indexSeq = floatList.toIndexedSeq 
        println("The converted indexed sequence is " + indexSeq) 


The converted indexed sequence is Vector(45.81, 12.56, 98.30)

Scala List Programs »


Comments and Discussions!


Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© some rights reserved.