This course is currently a work in progress. Please join the waitlist to receive regular updates.

Convert the case of a string in apex

In an enterprise application, data stored in the database must follow a consistent format. The Apex case conversion methods help in formatting characters by converting them to either lowercase or uppercase based on the circumstances.

Apex provides two built-in methods for case conversion:

  1. toUpperCase() which converts all characters to uppercase.
  2. toLowerCase() which converts all characters to lowercase.

Following is an example of converting the case of a string to uppercase in apex:

Loading...

In the above example:

  • In the above example, inputString, is a string variable with the default value 'Hello World'.
  • The toUpperCase() method is used to convert all characters in inputString to uppercase.
  • The variable outputString stores the result of the string conversion, which is then printed in the output using the system.debug() statement.

Try It Yourself

Loading...