v.f page:public class selectoptiontest {
public set<string>citylist {get;set;}
public set<selectoption>NotselectedOptions{get;set;}
public list<string>selectedvallist{get;set;}
public selectoptiontest(){
NotselectedOptions= new set<selectoption>();
selectedvallist= new list<string>();
citylist= new set<string>();
citylist.add('mumbai');
citylist.add('maharastra');
citylist.add('uttarpradesh');
citylist.add('mumbai');
getdata();
}
public void getdata(){
for(string s:citylist){
NotselectedOptions.add(new SelectOption(s,s));
}
}
public void removeselected(){
citylist.removeall(selectedvallist);
}
public void removeall(){
selectedvallist.clear();
for(string s:citylist){
selectedvallist.add(s);
}
citylist.removeall(selectedvallist);
}
}
can any one help it with it please.thanks and regardsfranklin.<apex:page controller="selectoptiontest" >
<apex:form >
<apex:outputPanel id="t">
<apex:selectList id="Avilblecities" multiselect="true" tabindex="1" value="{!selectedvallist}" >
<apex:selectOptions value="{!NotselectedOptions}"/>
</apex:selectList>
</apex:outputPanel>
<apex:commandButton action="{!removeselected}" rerender="t" value="removeselected"/>
<apex:commandButton action="{!removeall}" rerender="t" value="removeAll"/>
</apex:form>
</apex:page>
Hi Franklin,>> https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_methods_system_list.htmIn the documentation you can use the below functions for your purpose remove to delete a element at a particular index and clear function to remove all the elements in the list.remove(index)Removes the list element stored at the specified index, returning the element that was removed.Signaturepublic Object remove(Integer index)ParametersindexType: IntegerReturn ValueType: ObjectExample
clear():Removes all elements from a list, consequently setting the list's length to zero.Signaturepublic Void clear()Return ValueType: VoidEDIT: changed the clear description.Additionally, you can also try checking https://salesforce.stackexchange.com/questions/65670/best-way-to-remove-element-from-list-or-why-they-kept-iterator-without-this-optiLet me know if it helps you and close your query by marking it as solved so that it can help others in the future. Thanks.List<String> colors = new String[3];
colors[0] = 'Red';
colors[1] = 'Blue';
colors[2] = 'Green';
String s1 = colors.remove(2);
system.assertEquals('Green', s1);