Files
2025-02-05 04:43:28 +00:00

30 lines
1.2 KiB
HTML

<html>
<body>
Reports calls to <code>containsAll()</code> on <code>java.util.List</code>.
<p>
The time complexity of this method call is O(n&middot;m), where n is the number of elements in the list on which
the method is called, and m is the number of elements in the collection passed to the method as a parameter.
When the list is large, this can be an expensive operation.
</p>
<p>
The quick-fix wraps the list in <code>new java.util.HashSet&lt;&gt;()</code> since the time required to create
<code>java.util.HashSet</code> from <code>java.util.List</code> and execute <code>containsAll()</code> on
<code>java.util.HashSet</code> is O(n+m).
</p>
<p><b>Example:</b></p>
<pre><code> public boolean check(List&lt;String&gt; list, Collection&lt;String&gt; collection) {
// O(n&middot;m) complexity
return list.containsAll(collection);
}
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code> public boolean check(List&lt;String&gt; list, Collection&lt;String&gt; collection) {
// O(n+m) complexity
return new HashSet&lt;&gt;(list).containsAll(collection);
}
</code></pre>
<!-- tooltip end -->
<p><small>New in 2022.1</small></p>
</body>
</html>