function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manohar kumarManohar kumar 

Problem with reordering

Hi All,

I have a map Map<String, List<QuoteLineItem>>(). In key i am storing product2 name and in value its related lineItem for an quote.Its working fine and i am using this in a page.There is another object name Index_Order__c which has a lookup relationship with product2 and has a number field called Index.I want to rearrange the map based on the index. i did something like this to reslove this..

List<Index_Order__c> dup = [select Products,Index__c from Index_Order__c where Products IN :oldMap.keySet() order by Index__c];
        system.debug('###dup '+dup );
Map<String, List<QuoteLineItem>> newMap = new Map<String, List<QuoteLineItem>>();
        for(Index_Order__c p1:dup) {
            newMap.put(p1.Products,oldMap.get(p1.Products));
        }
        system.debug('###newMap'+neMap);
 

 but in debug map order is changged.I assume Map doesnot store order.Pls help me how to get resolve this...

pconpcon
As you expected, Maps do not store order.  What I would suggest you do is create a List that is your index and then use the list's order to then look up into your map.
Manohar kumarManohar kumar

Thanks for your reply  pcon.I figured that Map does not store order. i didnot think of making a list. i used a wrapper class instead.Again thanks for your reply.