You need to sign in to do that
Don't have an account?

Compare two lists
Hi Guys,
We have 2 lists one is a List of type string and other of type object. My requirement is to check if all values in string list exists in object list. If no then false.
List<string> A = new List<string>();
List<Contact> Contactlist = new List<Contact>();
Requirement: need to check if All values in the list A should exist in Contactlist if no then false.
Thanks,
Prasanna
We have 2 lists one is a List of type string and other of type object. My requirement is to check if all values in string list exists in object list. If no then false.
List<string> A = new List<string>();
List<Contact> Contactlist = new List<Contact>();
Requirement: need to check if All values in the list A should exist in Contactlist if no then false.
Thanks,
Prasanna
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm
NOTE :- As your your code you are trying to compare list of string with list if contact . In that which field you want to compare ?
IF both list are same then you can try below method if list
equals(list2)
Compares this list with the specified list and returns true if both lists are equal; otherwise, returns false.
list1.equals(list2);
Let us know if this will help you
Thanks
Amit Chaudhary
Make them into the same type, and then use containsAll() method in the Set to compare.Please check the below doc.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_set.htm
Best Regards,
Jyothsna
Pls tell which field from contact you want to check with the string list?
Thanks for replies.
Contact was an example but it is actually a custom object
List <custom_obj> ListB = new List<custom_obj>();
I only want to check if all values in the listA should exist in ListB not necessarily equal
ListA may contain (red, blue, black)
ListB may contain (red, black, blue, yellow, green)
Requirement: need to check if ListA has all values in ListB then true else false in the above example it should be true.
Say if ListB has (red, black) then it should be false.
Regards,
Prasanna
By any chance can you please give me an example code?
thanks,
Prasanna