Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to rearrange the elements in LinkedHashMap?

 
vicky saxena
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How Can I rearrange elements in LinkedHashMap i.e the shuffling of elements
can I insert the elements in between the LinkedHashMap
 
Scott Selikoff
author
Saloon Keeper
Posts: 4010
18
Eclipse IDE Flex Google Web Toolkit
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try an implementation of SortedMap such as TreeMap. You can control the ordering by having each object in the map implement the Comparable interface.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic