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
RajusRajus 

Case insensitivity with mapkeys.

Hi All,
I have one simple map like below.
Map<string,string> keyAndValues = new Map<string,string>();
keyAndValues.put('ABCD','1234');

Now i want to check whether the string 'abcd' exists in Keys of Map or not.
I ll write like this,
if(keyAndValues.containskey('abcd')){
    system.debug('Key exists in map');
}

Here It will return false as it ll check with case sensitivity.

But i want to ignore case sensitivity and want to search vth case insensivity.Is there any way to do like this.
If any one have idea please let me know.


Thanks in Advance.

Rajesh.
Best Answer chosen by Rajus
Gupta.VishalGupta.Vishal
Hi Rajesh ,
Map keys are case sensitive , you have to choose a format if you want case insensivity  for e.g.

use tolowercase() while putting and searching in Map
Map<string,string> keyAndValues = new Map<string,string>();
String key1='ABcd';

keyAndValues.put(key1.tolowercase(),'1234');

if(keyAndValues.containskey('abcd'.tolowercase()){
    system.debug('Key exists in map');
}