-2

I have a Map<Integer,List<SomeObject> map = new LinkedHashMap<Integer,List<SomeObject>>(); I was added elements in this order :

map.put(32,List Of SomeObjects);
map.put(2,List Of SomeObjects);
map.put(3,List Of SomeObjects);

after invoking this method via URL (Using restApi) I got map key in this order :

{2,List Of SomeObjects}
{3,List Of SomeObjects}
{32,List Of SomeObjects}

Can anyone tell me how to solve this problem ? Order of output is not order of input

Chala
  • 587
  • 1
  • 5
  • 11
  • What exactly is the problem here? Is it the different ordering? – Evan Knowles May 22 '14 at 08:03
  • Order of output is not order of input – Chala May 22 '14 at 08:04
  • Use a [SortedMap](http://docs.oracle.com/javase/7/docs/api/java/util/SortedMap.html). – Jens May 22 '14 at 08:07
  • 2
    I don't want output to be sorted. I want output in that order which is input – Chala May 22 '14 at 08:08
  • I will use my telepathic powers and guess that what the OP means is that he is invoking a REST method to which he passes the entire list (not a different invocation for each item), and in the process the rest API reorders the list. Otherwise it makes little sense. – SJuan76 May 22 '14 at 08:41

1 Answers1

1

Use this constructor

set the boolean to false

Rogue
  • 11,105
  • 5
  • 45
  • 71
Scary Wombat
  • 44,617
  • 6
  • 35
  • 64