How to check strings equal or not using apex in Salesforce?

How to check strings equal or not using apex in Salesforce?

1. equals()

Returns true if they are same and not null.

2. equalsIgnoreCase()

Returns true if they are same ignoring Case(Upper or Lower Case) and not null.

Sample Code:

String str1 = 'abc';
String str2 = 'ABC';
system.debug( str1.equals( str2 ) );
system.debug( str1.equalsIgnoreCase( str2 ) );

Output:

Leave a Reply