mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
29 lines
953 B
HTML
29 lines
953 B
HTML
<html>
|
|
<body>
|
|
Reports <code>List.remove(index)</code> called in a loop that can be replaced with <code>List.subList().clear()</code>.
|
|
<p>The replacement
|
|
is more efficient for most <code>List</code> implementations when many elements are deleted.</p>
|
|
<p>Example:</p>
|
|
<pre><code>
|
|
void removeRange(List<String> list, int from, int to) {
|
|
for (int i = from; i < to; i++) {
|
|
list.remove(from);
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>After the quick-fix is applied:</p>
|
|
<pre><code>
|
|
void removeRange(List<String> list, int from, int to) {
|
|
if (to > from) {
|
|
list.subList(from, to).clear();
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>
|
|
The quick-fix adds a range check automatically to prevent a possible <code>IndexOutOfBoundsException</code> when the minimal value is bigger
|
|
than the maximal value. It can be removed if such a situation is impossible in your code.
|
|
</p>
|
|
<!-- tooltip end -->
|
|
<p><small>New in 2018.2</small></p>
|
|
</body>
|
|
</html> |