This content has been marked as final. Show 2 replies
Based on which 'index'? The Map can hold any number of them, and at present you are taking an arbitrary one as returned by keySet().iterator().next(), which isn't guaranteed to give you any specific one of them.
The Map will always be a singletonMap so one key/value. The indexes are maintained across entries in the Collection not with in a single Map. BTW, I found out the problem was not the way it is sorting. In my scenario when this Collection is processed it is multithreaded and we lose the sorted entries to be processed in sequence.