+ Start a Discussion
Chandra Sekhar CH N VChandra Sekhar CH N V 

Convert Select Options to Set

I have a list of select options which I am displaying in a VF page as a multi picklist field. 
 
public List<SelectOption> getEPGName () {
        List<SelectOption> options = new List<SelectOption>();
        for (<sobject> EPG : <my query>]){
            options.add(new SelectOption(EPG.ID, EPG.<my field>));
        }
        SelectOptionSorter.doSort(options, SelectOptionSorter.FieldToSort.Label);
        return options;
}

How can I make it as a Set<string> so that the values will not be duplicated?
Le NguyenLe Nguyen
You donot need to convert it.  If you wish you to prevent duplicate, you can add to a set and check contains.
 
public List<SelectOption> getEPGName () {
        List<SelectOption> options = new List<SelectOption>();
        set<string> sString = new set<string>();
        for (<sobject> EPG : <my query>]){
            if(!sString.contains(EPG.<my field>)){
                 options.add(new SelectOption(EPG.ID, EPG.<my field>));
                 sString.add(PG.<my field>);
            }
        }
        SelectOptionSorter.doSort(options, SelectOptionSorter.FieldToSort.Label);
        return options;
}

Le