Range can be converted to indices or iteration
Reports until
and rangeTo
operators that can be replaced with Collection.indices
or iteration over collection inside for
loop.
Using syntactic sugar makes your code simpler.
The quick-fix replaces the manual range with the corresponding construction.
Example:
fun main(args: Array<String>) {
for (index in 0..args.size - 1) {
println(args[index])
}
}
After the quick-fix is applied:
fun main(args: Array<String>) {
for (element in args) {
println(element)
}
}
Inspection Details | |
---|---|
Available in: | IntelliJ IDEA 2023.3, Qodana for JVM 2023.3 |
Plugin: | Kotlin, @snapshot@ |
Last modified: 13 July 2023