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.
i declared and stored into array like this.
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"));
i tried like this
boolean hasCommonName = Cname.retainAll(Cnamedb);
if(hasCommonName){
out.println(Cname+"<br>");
out.println(hasCommonName);
}
boolean haspname=Pname.retainAll(Cnamedb);
if(haspname){
out.println(haspname);
}
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.
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.