![](https://www.infallibletechie.com/wp-content/uploads/2023/02/Convert-List-to-Set-in-Salesforce-1024x576.jpg)
To convert List to Set in Salesforce, add some values to List datatype and use addAll() to add it to Set datatype.
Sample Code:
List < String > tempList = new List < String >();
Set < String > tempSet = new Set < String >();
tempList.add( 'One' );
tempList.add( 'Two' );
tempList.add( 'One' );
System.debug(
'tempList is' + tempList
);
tempSet.addAll( tempList );
System.debug(
'tempSet is' + tempSet
);
tempList is List datatype and tempSet is Set datatype.
![](https://www.infallibletechie.com/wp-content/uploads/2023/02/Convert-List-to-Set-Salesforce-Apex.png)