function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
vasu takasivasu takasi 

how to remove a value from list without using its index

hi

 

i have a list like--       "list<string>options=new list<string>{'a','b','c','d','e','f','g','h'};"

 

from this list i want to remove "e" (lets assume that 'i have dont know its index')

 

 

Best Answer chosen by Admin (Salesforce Developers) 
vasu takasivasu takasi

just add all list values to a SET.

we can directly remove values from set using remove() method.

after that add this set to a perticuler list.

All Answers

HariDineshHariDinesh

Hi,

 

To this you can use APEX coding, For this

 

1)      Declare new List of same type.

2)      Loop through the List elements and if the element matches with your target element (In your case” e”) then don’t add that    element to your list, otherwise add elements to that new list.

3)      Now new list will be formed with your required values.

4)      Use new list or Assign new list to the old list (as you required).

 

Teach_me_howTeach_me_how

iterate to your list and call the .remove

vasu takasivasu takasi

just add all list values to a SET.

we can directly remove values from set using remove() method.

after that add this set to a perticuler list.

This was selected as the best answer