Map<String,String> mapvalue = new Map<String,String>();
for (string s : listorder){
mapvalue.put(s, fieldMap.get(s).getDescribe().getLabel());
}
Eg;list order is like B,A,C,D Output is like A,B,C,D
Map<String,String> mapvalue = new Map<String,String>();
for (string s : listorder){
mapvalue.put(s, fieldMap.get(s).getDescribe().getLabel());
}
Eg;list order is like B,A,C,D Output is like A,B,C,D
This is a side effect of the "Critical Update: Predictable Iteration Order for Apex Unordered Collections" and the subsequent patch "Iteration Order for Maps and Sets Is Now Predictable". The effects are described in this answer. Basically, the collection becomes sorted in order to provide consistent iteration results across multiple iterations, even in different transactions using the same data. There's no way to preserve the order you want by using a Map or Set.
If you must preserve the order of the values, you'll need to make it a list instead, perhaps with a wrapper class:
public class Wrapper {
public String value, label;
}
...
Wrapper[] values = new Wrapper[0];
for(String s: listOrder) {
Wrapper w = new Wrapper();
w.value = s;
w.label = fieldMap.get(s).getDescribe().getLabel();
values.add(w);
}