Kotlin ArrayList type toTypedArray convert Array

Kotlin ArrayList type toTypedArray convert Array

 

data class Point(val x: Float, val y: Float)

fun array_test(points: ArrayList<Array<Point>>) {
    points.forEachIndexed { idx, ap ->
        ap.forEach {
            print("$idx $it ")
        }

        println()
    }
}

fun main(args: Array<String>) {
    val p1 = arrayListOf(
        Point(0.0f, 0.0f),
        Point(0.1f, 0.1f),
        Point(0.5f, 0.5f),
    )

    val p2 = arrayListOf(
        Point(0.6f, 0.6f),
        Point(1.0f, 1.0f),
    )

    array_test(arrayListOf(p1.toTypedArray(), p2.toTypedArray()))
}

 

0 Point(x=0.0, y=0.0) 0 Point(x=0.1, y=0.1) 0 Point(x=0.5, y=0.5) 
1 Point(x=0.6, y=0.6) 1 Point(x=1.0, y=1.0) 

 

 

 

kotlin forEachIndexed arrayListOf<String>-CSDN BlogThe article has been viewed and read 129 times. zip_python zip function in Python for loop is used in for loop_zhangphil's blog-CSDN blog. https://blog.csdn.net/zhangphil/article/details/131003571

The flat MutableList element is inserted into a new MutableList every few elements, Kotlin-CSDN blogThe article has been viewed and read 1.1k times, liked 19 times, and collected 23 times. Given a length value of length, split the list into N-segment lists each of length length, Kotlin_zhangphil's blog-CSDN blog. The flat MutableList element is packed into a new MutableList every few elements, Kotlin. The article has been viewed and read 652 times. Total length: 22 Randomly generated length of each segment: 4 Calculated number of segments: 6. https://blog.csdn.net/zhangphil/article/details/134517311

 

Guess you like

Origin blog.csdn.net/zhangphil/article/details/135034214