I am trying to add a List of collection to a Map Collection with the same Index. I have this Code: List<Account> accountContactList = [SELECT Id,Name FROM Account]; Map<Integer,List<Account>> objWrapper = new Map<Integer,List<Account>>(); List<Account> listToMapCOllection = new List<Account>(); for(Account accCont: accountContactList){ if(counterToViewPerPage <= viewPerPage){ listToMapCOllection.add(accCont); counterToViewPerPage++; }else{ objWrapper.put(counterIndex,listToMapCOllection); counterIndex++; counterToViewPerPage = 1; listToMapCOllection.clear(); } } Now my problem is when the result of accountContactList Collection is only 2 or the size of the collection is an ODD, the code will nerver go to else condition and it will not add to my Map Collection (objWrapper ). Any help please.