Array/List iteration without extra object allocations

To iterate an array without allocating extra objects you can use one of the following ways.

  1. for-loop
    for (e in arr) {
        println(e)
    }
  1. forEach extension
    arr.forEach {
        println(it)
    }
  1. forEachIndexed extension, if you need to know index of each element
    arr.forEachIndexed { index, e ->
        println("$e at $index")
    }

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)