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
jagadeep kjagadeep k 

compare two lists and remove records which are common in both lists from list1

I have two lists of dates list one contains 100 days dates from tomorrow and list two contains dates which come from api that contains holidays and weekends. I need to compare both the lists and remove second list values from the first list. I have tried to compare and remove but it is not giving proper result.Please help me how to do it in apex. 
Santoshi K VSantoshi K V
List<String> list1 = new List<String>{'test1','test2','test3','test4'};
List<String> list2 = new List<String>{'test1','test3'};
Set<String> set1 = new Set<String>(list1); // Copy the list as a set.
set1.removeAll(list2); // Remove the items from list2.
system.debug(set1); // Set1 contains {'test2','test4'}