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)
}
}
Locating this inspection
- By ID
Can be used to locate inspection in e.g. Qodana configuration files, where you can quickly enable or disable it, or adjust its settings.
ReplaceManualRangeWithIndicesCalls- Via Settings dialog
Path to the inspection settings via IntelliJ Platform IDE Settings dialog, when you need to adjust inspection settings directly from your IDE.
Inspection Details | |
---|---|
By default bundled with: | |
Can be installed with plugin: | Kotlin, 242.22892-IJ |
Last modified: 11 September 2024