0

I have the following problem: I have a HashMap

HashMap <String, BeanRelEstatisticaMateriaPrima> dataBeanList = new HashMap ();

And I am generating an iReport report, but to send the data to the report, I do a HashMap conversion to an ArrayList:

List <BeanRelEstatisticaMateriaPrima> test = new ArrayList <BeanRelEstatisticaMateriaPrima> (dataBeanList.values ());

JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource (test);

But in doing this conversion, ordination is being lost. In the hashmap I have in alphabetical order, eg: (A, B, C, D, E) but in the ArrayList it gets (D, A, E, C, B)

Is there a way to transform to ArrayList by keeping the sort order exactly the same as HashMap?

Alex K
  • 21,796
  • 18
  • 106
  • 231
Geizon T.
  • 11
  • 5

1 Answers1

2

HashMaps do not guarantee order. Use a LinkedHashMap if you want to preserve order of insertion.

Solace
  • 2,151
  • 1
  • 14
  • 32