title: What is the time complexity of using retainAll() function between List and HashMap?
body: <p>Let's say i have a nested List which contains n^2 element in it and also i have a HashMap which contains n^2 keys in it. I want to get common elements between the list and hashmap with using <code>retainAll()</code> function. What is the time complexity of retainAll() in this case?</p>
  <pre><code>List&lt;List&lt;Integer&gt; list = new ArrayList&lt;&gt;();
  Map&lt;List&lt;Integer&gt;, Integer&gt; hashmap = new HashMap&lt;List&lt;Integer&gt;, Integer&gt;();
  list.retainAll(hashmap);
  </code></pre>
  <p>To get the commons,i'm using this loop but it has n^2 complexity.</p>
  <pre><code>List&lt;List&lt;Integer&gt;&gt; commons = new ArrayList&lt;&gt;();
  
      for (int i = 0; i &lt; list.size(); i++) {
          if (hashmap.get(list.get(i)) != null) {
              commons.add(list.get(i));
          }
      }
  </code></pre>
  <p>Also if you have an algorithm which has better time complexity  to get intersection of them, i need it.</p>
  <p><strong>EDIT :</strong>
  Actually the problem is , i have a list of integers size of n . But i divided that list into sublists and sublists count became n^2. Since i want to find out that hashmap contains every sublist as a key in it, i used n^2 in question. But it's too big according to my whole project. I'm searching complexity decreasing ways.</p>