Вы найдете хорошее использование forEachIndexed(action: (index: Int, T) -> Unit): Unit
и оператора модуля (%
) в этом случае. Вы можете сделать так:
val mList = arrayListOf(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"
)
val aList = arrayListOf(
"1", "2", "3", "4", "5"
)
fun main() {
val arrayList = arrayListOf<ArrayList<String>>()
mList.forEachIndexed { index, s -> arrayList.add(arrayListOf(s, aList[index % aList.size])) }
println(arrayList) // [[a, 1], [b, 2], [c, 3], [d, 4], [e, 5], [f, 1], [g, 2], [h, 3], [i, 4], [j, 5], [k, 1]]
}