Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Are these really <a href="http://java.sun.com/javase/6/docs/api/java/util/List.html" rel="noreferrer">lists</a> (ordered, with duplicates), or are they <a href="http://java.sun.com/javase/6/docs/api/java/util/Set.html" rel="noreferrer">sets</a> (unordered, no duplicates)?</p> <p>Because if it's the latter, then you can use, say, a <a href="http://java.sun.com/javase/6/docs/api/java/util/HashSet.html" rel="noreferrer"><code>java.util.HashSet&lt;E&gt;</code></a> and do this in expected linear time using the convenient <a href="http://java.sun.com/javase/6/docs/api/java/util/Set.html#retainAll(java.util.Collection)" rel="noreferrer"><code>retainAll</code></a>.</p> <pre><code> List&lt;String&gt; list1 = Arrays.asList( "milan", "milan", "iga", "dingo", "milan" ); List&lt;String&gt; list2 = Arrays.asList( "hafil", "milan", "dingo", "meat" ); // intersection as set Set&lt;String&gt; intersect = new HashSet&lt;String&gt;(list1); intersect.retainAll(list2); System.out.println(intersect.size()); // prints "2" System.out.println(intersect); // prints "[milan, dingo]" // intersection/union as list List&lt;String&gt; intersectList = new ArrayList&lt;String&gt;(); intersectList.addAll(list1); intersectList.addAll(list2); intersectList.retainAll(intersect); System.out.println(intersectList); // prints "[milan, milan, dingo, milan, milan, dingo]" // original lists are structurally unmodified System.out.println(list1); // prints "[milan, milan, iga, dingo, milan]" System.out.println(list2); // prints "[hafil, milan, dingo, meat]" </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload