I am trying to reduce the searching area inside a loop once i have satisfied some condition. That means i want to reduce the size of the map by removing the keys in it. Those keys and the related data have already been processed so i am thinking it is unnecessary to having them in the map and try to avoid going through them once again inside the loop. Is that possible? Please suggest.
Here, mpSFDCSAP is a map.
for(SAP_Customer_Master__c s: mpSFDCSAP.values()) {
String[] strArr2 = s.Customer_Name__c.split(' ');
String strCustName = '';
if((strArr2[0].length()==1 && strArr2[0].StartsWith('A')) || (strArr2[0].length()==3 && strArr2[0].StartsWith('The'))) {
strCustName = strArr2[1].toLowerCase();
}else{
strCustName = strArr2[0].toLowerCase();
}
if(strCustName.startsWith(strAccName)) {
lstSAPCustMast.add(s);
}
mpSFDCSAP.remove(some keys);
//I am thinking the above line would reduce my map size
//and improve the performance of the loop by
//preventing to lookup the visited records once again.
//Does it work inside the context of a loop, because loop variable is the map itself
}