Ads

Friday, 3 May 2013

Convert List to Set in Salesforce?

The simplest way to convert List to Set in Salesforce is given below:       

        List<String> tempList = new List<String>();
        Set<String> tempSet = new Set<String>();
        
        tempList.add('One');
        tempList.add('Two');
        tempList.add('Three');  
        
        tempSet.addAll(tempList); 


tempList is List datatype and tempSet is Set datatype.
Add some values to List datatype and use addAll() to add it to Set datatype.

1 comment:

  1. Why not

    Set tempSet = new Set(tempList )

    ?

    I think that would be really the simplest way.

    ReplyDelete