1. put the keys and values in different collections
2.sort the values
3.iterate through sorted values,then iterate through the key set.
4.get the value from the unsorted map w.r.t to the key iteration
5.compare the value with the iterated value.
6.put the key and value into a sorted map if the comparison succeeds.
when i print the key an value after the successful comparison, i get the out put as required,i.e the output is sorted w.r.t. values.
but when the same output is inserted into a sorted map. I get the output as sorted w.r.t. keys.
what am i missing here.Is there a map which give the output in first in first out pattern
A linked hash map isn’t sorted; it is ordered. Sorted means you keep the keys from smallest to largest. A linked hash map keeps them from first inserted to last inserted. If you really want sorting, look for a Sorted Map and that link will give hints about which classes you can use.
Joined: Aug 22, 2008
yes Ritchie, you are right.But i had sorted the values already using comparator and wanted a map with FIFO.
Joined: Oct 13, 2005
Maps don’t implement FIFO; lists do. But your linked hash map is a combination of a map and a list, so the list bit can implement FIFO for you.