+ 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) {

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

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.