Clean up a sentence by trimming it and reducing every sequence of whitespace characters (spaces, tabs, or newlines) to a single space. Return null when the input is null.
Examples:
String text = ' Salesforce Apex Challenge '; String normalized = normalizeWhitespace(text); // Results: 'Salesforce Apex Challenge' String text = 'Lines with Tabs'; String normalized = normalizeWhitespace(text); // Results: 'Lines with Tabs'
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.