Swap the case of every letter in the input string. Uppercase letters become lowercase and lowercase letters become uppercase. Non-letter characters such as digits, spaces, and symbols remain unchanged. Return null for null input and an empty string for an empty input.
Examples:
Input: str = 'Hello World'
Output: 'hELLO wORLD'
Explanation: Each letter is converted to its opposite case while the space remains unchanged
Input: str = 'ABC'
Output: 'abc'
Explanation: All uppercase letters become lowercase
Input: str = 'Java123!'
Output: 'jAVA123!'
Explanation: Letters swap case, digits and symbols stay the same
Input: str = null
Output: null
Explanation: Null input returns null
Input: str = ''
Output: ''
Explanation: Empty string returns empty string
Apex Code Editor
Welcome to Lightning Challenge!
How It Works
- • Write your solution in the code editor
- • Connect your Salesforce org to test
- • Submit to check if your solution passes
- • Use hints if you get stuck
Contest Alert
🏆 #CodeEveryDay July 2026
Contest runs July 1 - 31. Complete challenges to climb the leaderboard!
Only the 31 daily challenges shown during this contest count toward points. Earlier dailies don't carry over.