扁平的MutableList元素每隔若干元素一组装入新MutableList,Kotlin

扁平的MutableList元素每隔若干元素一组装入新MutableList,Kotlin

Kotlin 复制代码
fun main(args: Array<String>) {
    val array = arrayOf("a", "b", "c", "d", "e", "f", "g", "h", "i", "j")
    val STEP = 3 //3个元素一组
    var k = 0
    val lists = mutableListOf<MutableList<String>>()

    for (i in array.indices step STEP) {
        val temp = mutableListOf<String>()

        for (j in 0 until STEP) {
            k = i + j
            if (k >= array.size) {
                break
            }
            temp.add(array[k])
        }

        lists.add(temp)
    }

    lists.forEachIndexed { index, s ->
        println(s)
    }
}

a, b, c

d, e, f

g, h, i

j

Android Glide自定义AppCompatImageView切分成若干小格子,每个小格子onDraw绘制Bitmap,Kotlin(1)-CSDN博客文章浏览阅读386次,点赞5次,收藏6次。垂直方向的RecyclerView,每行一个AppCompatImageView,每个AppCompatImageView被均匀切割成n个小格子, 每个小格子通过Glide加载出来Bitmap,然后onDraw绘制整行。//读取所有图片!//路径 uri//图片名称//图片大小= null,const val ROW_SIZE = 16 //一行多少个bitmap。https://blog.csdn.net/zhangphil/article/details/134519527

给定长度值length,把列表切分成每段长度为length的N段列表,Kotlin_zhangphil的博客-CSDN博客文章浏览阅读652次。总长度:22 随机生成每段长度:4 算出段数:6。https://blog.csdn.net/zhangphil/article/details/131999459

相关推荐
糖猫猫cc7 小时前
Kite:填充处理器
kotlin·orm·kite
Kapaseker14 小时前
一杯美式深入理解 data class
android·kotlin
alexhilton3 天前
端侧RAG实战指南
android·kotlin·android jetpack
Kapaseker4 天前
2026年,我们还该不该学编程?
android·kotlin
Kapaseker5 天前
一杯美式搞懂 Any、Unit、Nothing
android·kotlin
Kapaseker6 天前
一杯美式搞定 Kotlin 空安全
android·kotlin
FunnySaltyFish6 天前
什么?Compose 把 GapBuffer 换成了 LinkBuffer?
算法·kotlin·android jetpack
Kapaseker7 天前
Compose 进阶—巧用 GraphicsLayer
android·kotlin
Kapaseker7 天前
实战 Compose 中的 IntrinsicSize
android·kotlin
A0微声z9 天前
Kotlin Multiplatform (KMP) 中使用 Protobuf
kotlin