0

I am losting soft order of my list as I convert to Map.. How else can I do this... Spring needs my list as a Map for my dropbox

Map<String, String> selectableReporters = new HashMap<String, String>();
List<NameID_lookupModel> lstReports = database.getSelectableReporters();

for (NameID_lookupModel i : lstReports) selectableReporters.put(i.getID(), i.getName() + " - " + i.getID());
Johnathan Smith
  • 1,112
  • 2
  • 17
  • 34

1 Answers1

1

LinkedHashMap instead HashMap may help if the content is already sorted and in the order you want to display. LinkedHashMap keeps insertion order.

LinkedHashMap<String, String> insertionOrderMap = new LinkedHashMap<String, String>();

If your list is already sorted, Iterate over list and add to LinkedHashMap

Add list items to above map.

kosa
  • 65,990
  • 13
  • 130
  • 167