Compare two List

Sathish David  Kumar N
Sathish David  Kumar N used Ask the Experts™
Hi ,

I want to compare two list values  How can i compare without for  loop !!
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
what is this i didnt get ur answer !!
there is nothing related my question Mr.xpertoPC
Top Expert 2009

How do you want to compare them? List A and List B?
-> check whether all elements in list A are list ?
-> elements in list A not in list B?
-> elements in list B not in list A?
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

Top Expert 2009

Here is a small code snippet that you can use -

ArrayList<String> a = new ArrayList<String>();
ArrayList<String> b = new ArrayList<String>();
a.removeAll(b); // This removes all elemets in a that are present in B so you get the difference
Hi A_b
Ya i want to check wether   a ArrayList having values of  b ArrayList  if there means i want to store in new array list
Top Expert 2009

Write your logic using the code snippet above, that should solve your problem easily.
List a=new ArrayList();
            List b=new ArrayList();
            List c=new ArrayList();

i want to store same values of  a,b arraylist  in c
how can we do with out  for loop
Top Expert 2009
Make a copy of a as a_temp;


Now a will have all the values common to a and b. Copy a over to c.
But a  arraylist value are dleted as per ur code !!
so i add all contant to c arraylist and remove from a _temp arraylist

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial