Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>EDIT</strong></p> <p>Here are two versions. One using <code>ArrayList</code> and other using <code>HashSet</code> </p> <p>Compare them and create your <strong>own</strong> version from this, until you get what you need. </p> <p>This should be enough to cover the:</p> <blockquote> <p><em>P.S: It is not a school assignment :) So if you just guide me it will be enough</em></p> </blockquote> <p>part of your question.</p> <p><strong>continuing with the original answer:</strong> </p> <p>You may use a <code>java.util.Collection</code> and/or <code>java.util.ArrayList</code> for that. </p> <p>The <a href="http://java.sun.com/javase/6/docs/api/java/util/Collection.html#retainAll%28java.util.Collection%29" rel="noreferrer">retainAll</a> method does the following:</p> <blockquote> <p><em>Retains only the elements in this collection that are contained in the specified collection</em></p> </blockquote> <p>see this sample:</p> <pre><code>import java.util.Collection; import java.util.ArrayList; import java.util.Arrays; public class Repeated { public static void main( String [] args ) { Collection listOne = new ArrayList(Arrays.asList("milan","dingo", "elpha", "hafil", "meat", "iga", "neeta.peeta")); Collection listTwo = new ArrayList(Arrays.asList("hafil", "iga", "binga", "mike", "dingo")); listOne.retainAll( listTwo ); System.out.println( listOne ); } } </code></pre> <p><strong>EDIT</strong></p> <p>For the second part ( similar values ) you may use the <a href="http://java.sun.com/javase/6/docs/api/java/util/Collection.html#removeAll%28java.util.Collection%29" rel="noreferrer">removeAll</a> method:</p> <blockquote> <p><em>Removes all of this collection's elements that are also contained in the specified collection.</em></p> </blockquote> <p>This second version gives you also the similar values and handles repeated ( by discarding them).</p> <p>This time the <code>Collection</code> could be a <code>Set</code> instead of a <code>List</code> ( the difference is, the Set doesn't allow repeated values ) </p> <pre><code>import java.util.Collection; import java.util.HashSet; import java.util.Arrays; class Repeated { public static void main( String [] args ) { Collection&lt;String&gt; listOne = Arrays.asList("milan","iga", "dingo","iga", "elpha","iga", "hafil","iga", "meat","iga", "neeta.peeta","iga"); Collection&lt;String&gt; listTwo = Arrays.asList("hafil", "iga", "binga", "mike", "dingo","dingo","dingo"); Collection&lt;String&gt; similar = new HashSet&lt;String&gt;( listOne ); Collection&lt;String&gt; different = new HashSet&lt;String&gt;(); different.addAll( listOne ); different.addAll( listTwo ); similar.retainAll( listTwo ); different.removeAll( similar ); System.out.printf("One:%s%nTwo:%s%nSimilar:%s%nDifferent:%s%n", listOne, listTwo, similar, different); } } </code></pre> <p>Output:</p> <pre><code>$ java Repeated One:[milan, iga, dingo, iga, elpha, iga, hafil, iga, meat, iga, neeta.peeta, iga] Two:[hafil, iga, binga, mike, dingo, dingo, dingo] Similar:[dingo, iga, hafil] Different:[mike, binga, milan, meat, elpha, neeta.peeta] </code></pre> <p>If it doesn't do exactly what you need, it gives you a good start so you can handle from here. </p> <p>Question for the reader: How would you include all the repeated values?</p>
    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. 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