Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to make the set to display as Unorderlist. So that it will display the values in an order that I have initialized.

Is there any way to achieve it?

Set<String> values = new Set<String>{'SZ','SA','EL','SP','DP'};
share|improve this question

Sets are unordered lists that don't contain duplicates. If you want to maintain the order, use a List.

share|improve this answer

Sets are un-ordered by their very nature. If you need an ordered list you should use a List<String> collection. If you need to ensure things are unique and other set features, then you can just get a list for rendering only by adding all of the set elements to a list:

public List<String> getOrderedList()
  List<String> orderedValues = new List<String>();
  return orderedValues;

In your scenario you probably don't want the elements sorted alphabetically, so you'd be better off initialising the list first, and then adding all the list's elements to a set if that functionality is required.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.