Alex Rivera | Logout

How do i parse a map (foreach) in the same order i created it (JAVA)

Asked 2010-05-22T23:58:52.053
9

So i have a map that i created (inserted data) in an order i wanted. When parsing the map the 1st key returned in foreach is not the first key i inserted. Is there a way for that to happen?

Also sorting my map is kinda tricky cause it has to be sorted by Value and in specific field within the Value. Ty

Edit
Report

1 Answer

6

Check out LinkedHashMap for a Map implementation with predictable iteration order. You also might consider just using a List if you're not actually doing lookup by keys.

answered 2010-05-23T00:02:56.507

Your Answer