title: Compare two different ArrayLists for matching element
body: <p>I have two array list I want to compare the requested element against the allowed element. </p>
  
  <p>If requested element is present in the allowed elements it should print </p>
  
  <pre><code>"Allowed elements  &lt;element1&gt;, &lt;element2&gt;, &lt;element3&gt;"
  </code></pre>
  
  <p>and </p>
  
  <p>If requested element is not present in the allowed elements it should print</p>
  
  <pre><code>"Not allowed &lt;element1&gt;, &lt;element2&gt;, &lt;element3&gt;"
  </code></pre>
  
  <p>My Code</p>
  
  <pre><code>public class testList {
  
      public static void main(String[] args) {
  
          ArrayList&lt;String&gt; Alist = new ArrayList&lt;String&gt;();
          ArrayList&lt;String&gt; Blist = new ArrayList&lt;String&gt;();
  
          // allowed elements
          Alist.add("NAME");
          Alist.add("SUBJECT");
          Alist.add("MARKS");
  
          // requested elements
          Blist.add("NAME");
          Blist.add("AGE");
          Blist.add("DOB");
          Blist.add("SUBJECT");
          Blist.add("MARKS");
          Blist.add("AVERAGE");
          Blist.add("MOBILE");
          Blist.add("EMAIL");
  
      }
  }
  </code></pre>
  
  <p>and the result should be:</p>
  
  <p>If EMAIL and MOBILE are requested which is not in allowed elements should print "<strong>Not allowed EMAIL and MOBILE</strong>"</p>
  
  <p>If NAME, SUBJECT and MARKS are requested which are allowed elements should print "<strong>Allowed NAME, SUBJECT and MARKS</strong>"</p>