Skip to main content

Posts

Showing posts with the label map method

How contains key method works ? Does it allow partial matches or exact matches ?

This might be very simple, Even I was also thinking as the method name is "containskey" then it should return true if partial matches, unfortunately it is not like that. "Containskey" method will return true only if key is exact match. It is also case sensitive. Below is some code snippet map<string,string> test = new map<string,string>(); test.put('abc123','GM'); system.debug('Exact matches -abc123 -'+test.ContainsKey('abc123'));---- True system.debug('Partial matches-123--'+test.ContainsKey('123')); --- False system.debug('Partial matches-abc--'+test.ContainsKey('abc')); --- False system.debug('Case sensitive matches-ABC123-- '+test.ContainsKey('ABC123')); --- False