[SalesForce] List to String – Join to a comma and quotes

To do a Join From List to a String separated with commas we need to do the following:

String someStringVar = String.join(SomeList, ',');

But If I want to make a Join with Comma and Quotes?

For Example :

 List<String> StringList = new List<String>{'1','2','3'};

and the ouput should be :

'ag03','ag05','ag06','ag07','ag08','ag09','ag10','ex01','ex02','hu01'

as one String.

I'm asking that because I want to make a query on multi picklist.

****EDIT : Base on the Answer of @Mariia Illarionova ****

For querying a multi picklist field :

 String StringVar= '\'' + String.join(asd, '\',\'') + '\'';
    List<Object__c> inti = [SELECT Id,Agriculture__c FROM Interest__c WHERE Active__c = true AND  Agriculture__c INCLUDES (:StringVar)];

Which does not work

But this is Work:

List<Object__c> inti = [SELECT Id,Agriculture__c FROM Interest__c WHERE Active__c = true AND  Agriculture__c INCLUDES ('ag03','ag05','ag06','ag07','ag08','ag09','ag10','ex01','ex02','hu01')]; 

Can anyone tell me why please?

Best Answer

That's quite a simple solution for this (also with join as you stated):

List<String> stringList = new List<String>{'1','2','3'};

String result = '\'' + String.join(stringList, '\',\'') + '\'';

system.debug(result);