A few years back, there was a release that made Maps and Set ordered like list, But it looks like it's not the case anymore.
Set<String> newSet = new Set<String>();
newSet.add('Experian');
newSet.add('Equifax');
System.debug(newSet); //Prints {Equifax, Experian} instead of right order.
The reason I wanted to use set was to not let duplicate values, but let the order maintained. Am I doing something stupid?
Edit: It looks like when you iterate it in For loop FIFO order is maintained.
Set<String> newSet = new Set<String>();
newSet.add('Experian');
newSet.add('Equifax');
newSet.add('Transunion');
for(String str : newSet){
System.debug(str);
}
System.debug(newSet);
OP :
Experian
Equifax
Transunion
{Equifax, Experian, Transunion}
Edit 2: Checking if 2 sets having identical values iterate in same order
Set<String> newSet1 = new Set<String>();
newSet1.add('Experian');
newSet1.add('Equifax');
newSet1.add('Transunion');
for(String str : newSet1){
System.debug(str);
}
System.debug(newSet1);
Set<String> newSet2 = new Set<String>();
newSet2.add('Transunion');
newSet2.add('Experian');
newSet2.add('Equifax');
for(String str : newSet2){
System.debug(str);
}
System.debug(newSet2);
OP :
Experian
Equifax
Transunion
{Equifax, Experian, Transunion}
-----------------------------------
Transunion
Experian
Equifax
{Equifax, Experian, Transunion}