Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Collection.unmodifiableMap iteration order

Does Colelction.unmodifiableMap safeguard the iteration order?

I was trying newMap.put(key,Collections.ModifiableMap(oldMap)) Then when I do newMap.get(key) and iterate, iterate order seems to change.

How can we protect the iterate order?

like image 543
Chandra Avatar asked Mar 04 '11 01:03

Chandra


1 Answers

UnmodifiableMap simply delegates all methods, except writing ones. It's order is exactly that of the delegate.

If you need to have the same order as the first collection, use LinkedHashMap.

like image 91
Lundberg Avatar answered Sep 27 '22 23:09

Lundberg