I want to get index list as follows.
val a = booleanArrayOf(true,false,true,false)
above code, True number is two. -> indexList = {0, 2} how to get indexList in Kotlin.
You could use mapIndexed() to get the index and the value of each element, convert to either the index or null, and then remove the nulls...
val b: List<Int> = a.mapIndexed { i, b -> if (b) i else null }.filterNotNull().toList()
Another way would be to use the withIndex() function, filter the values that are true, and map the resulting pairs to the index value. This might be a bit clearer.
val c: List<Int> = a.withIndex().filter { it.value }.map { it.index }
val indexList: List<Int> = yourList.withIndex().filter { (!it.value.your_custom_object!!.keyName.equals("") && it.value.your_custom_object!!.keyName!!.equals( "some_value", ignoreCase = true )) }.map { it.index }