how to get common elements from string arraylist
<p>i have 3 string list called Cname,cnamedb,Pname. These 3 lists has a result obtained by query the SQL database.cname and Pname results are getting from querying excel database. cnamedb  result is getting from querying SQL database. </p>

<p>i declared and stored into array like this.</p>

<pre><code> List Cname = new  ArrayList();
 List Pname =new ArrayList();
 List cnamedb=new  ArrayList();

  Cname.add(rs.getString("Cname"));
  Pname.add(rs.getString("Pname"));
  cnamedb.add(res.getString("Cname"));
</code></pre>

<p>i tried like this</p>

<pre><code>        boolean hasCommonName = Cname.retainAll(Cnamedb);
         if(hasCommonName){
          out.println(Cname+"&lt;br&gt;");
         out.println(hasCommonName);
      }
       boolean haspname=Pname.retainAll(Cnamedb);
      if(haspname){
     out.println(haspname);
     }
</code></pre>

<p>This is just giving me a answer true for the first if statement but not printing the list elements. for the second if statements no results am getting.</p>

<p>i need to find out common elements exists in database and the excel, first i need to get common elements from Cname and Cnamedb and then from Pname and Cnamedb. how do i get the common elements.please provide me the code snippet. </p>
