function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AkshiiiiiAkshiiiii 

how to compare two lists in apex

Hi,
How can I compare a list which is taken as an input from the user to the list of values in a field of a custom object? 
CharuDuttCharuDutt
Hii Akshii
Try Below Code
list<String> lst1 = new list<String>{'1','2','3'};
            list<String> lst2 = new list<String>{'1','2'};


for(integer i = 0; i<lst1.size(); i++)
{

if(lst2.contains(string.valueof(lst1[i])))
{
System.debug('Heeeeeeee'+i);
}
}
Please Mark It As Best Answer If It HelpsThank You!
 
Suraj Tripathi 47Suraj Tripathi 47
Hi Akshiii,
 
list<String> s1 = {1,2,3,4,5,6}
list<String> s2 = {2,3,6,1}
String[] st = s1.split(' , ');
for(integer i = 0; i<st1.size(); i++)
{

if(S2.contains(string.valueof(st[i])))
{

}
}

If you find your Solution then mark this as the best answer. 

Thank you!

Regards 
Suraj Tripathi