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
chaitanyakuamar Teruchaitanyakuamar Teru 

apex development code

list<String> f1=new list<String>{'red','blue','yellow','orange'};
 list<String>s1=new list<String>{'blue','black','yellow','green','blue'};
         
Q.compare both list's & print the common values along with count 
SwethaSwetha (Salesforce Developers) 
HI Chaitanya,
The approach in https://salesforce.stackexchange.com/questions/9910/comparing-values-between-two-lists should help you get started.
Map<String, Obj__c> objMap1 = new Map<String, Obj__c>();
Map<String, Obj__c> objMap2 = new Map<String, Obj__c>();

// List 1
for(Obj__c o : list1)
{
    objMap1.put(o.UniqueName__c, o);
}

// List 2
for(Obj__c o : list2)
{
    objMap2.put(o.UniqueName__c, o);
}

// Now you can easily check if that value is in your map by doing.
objMap1.containsKey('WhateverYouWantToCompare');
// or
objMap2.containsKey(newObj.UniqueName__c);

// ... do your logic
Related: https://trailblazers.salesforce.com/answers?id=90630000000i8heAAA

https://developer.salesforce.com/forums/?id=9060G000000BeDbQAK

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you