You need to sign in to do that
Don't have an account?
Rajeev Satapathy
Compare two list in Apex
I want to compare two list in which values are stored in a different order . I am inserting the list into different maps . how to compare that the data in list 1 is present in list 2.
As you cannot directly sort a map, you have to search each member of list1 in list2.
Also you can copy the desired data from your maps to lists which then can be sorted using sort method.
After that, you can search for each list1 members in list2 using contains method.
Hope this helps,
Fred
All Answers
As you cannot directly sort a map, you have to search each member of list1 in list2.
Also you can copy the desired data from your maps to lists which then can be sorted using sort method.
After that, you can search for each list1 members in list2 using contains method.
Hope this helps,
Fred
Thanks,
Fred
First, convert these two list to Set. You can use "Set<String> theSet = new Set<String>(theList);" to do this.
Second, loop through the new Set 1, check whether that individual value is contained in Set 2 using "theSet2.contains(X)"