aspose file tools*
The moose likes Java in General and the fly likes How to rearrange the elements in LinkedHashMap? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to rearrange the elements in LinkedHashMap?" Watch "How to rearrange the elements in LinkedHashMap?" New topic
Author

How to rearrange the elements in LinkedHashMap?

vicky saxena
Greenhorn

Joined: Aug 23, 2005
Posts: 15
How Can I rearrange elements in LinkedHashMap i.e the shuffling of elements
can I insert the elements in between the LinkedHashMap
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3707
    
    5

I don't believe you can, as LinkedHashMap only maintains insertion order and does have any methods for inserting between elements. You should either use a different collections class, or rebuild the LinkedHashMap (can be expensive if this is frequent).


My Blog: Down Home Country Coding with Scott Selikoff
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Try an implementation of SortedMap such as TreeMap. You can control the ordering by having each object in the map implement the Comparable interface.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to rearrange the elements in LinkedHashMap?