You need to sign in to do that
Don't have an account?
Nitish 73
Comparing 2 lists
Hi Everyone,
I have 2 lists of type String and I want to compare both of them and see if the elements inside them match and return something.
Here is the code snippet.
The order doesnt matter, all I need to check is 'Do the elements in lineside list match with elements in dmside' . How can I compare them and achieve this.
Any help is appreciated.
Thanks
I have 2 lists of type String and I want to compare both of them and see if the elements inside them match and return something.
Here is the code snippet.
List<Required_Documents__c> Docslist = [SELECT ID, Decision_Matrix__c, Required_Docs__c FROM Required_Documents__c WHERE Decision_Matrix__c IN: DMList]; List<String> dmside = new List<String>(); for(Required_Documents__c req : Docslist){ dmside.add(req.Required_Docs__c); } //output of dmside ----- Health Certificate; Medical History Certificate ; Treatment Certificate List<Applicant_Attachments__c> Lineattachments = [SELECT ID, Document_Types__c FROM Applicant_Attachments__c WHERE AC__c=:LineList[0].Id]; List<String> lineside = new List<String>(); for(Applicant_Attachments__c a: Lineattachments){ lineside.add(a.Document_Types__c); } //output of lineside ----- Health Certificate; Treatment Certificate; Medical History Certificate
The order doesnt matter, all I need to check is 'Do the elements in lineside list match with elements in dmside' . How can I compare them and achieve this.
Any help is appreciated.
Thanks
You can use containsAll() method in the Set to compare, doc,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_set.htm
Regards,
Mahesh
All Answers
You can use containsAll() method in the Set to compare, doc,
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_set.htm
Regards,
Mahesh
If you think that your list doesn't care about unique valuse then you can go with Set. Multiple occurrance of a value like 'Health Certificate' will be treates as a single element in Set.
You can try below code.
I hope this will work for you.
Thanks & Regards,
Naval
It worked. Much appreciated :)