Concatenating strings in Apex with "+" operator or String.join() can be full of pain. Unwanted spaces and commas. Empty or null strings. Ugly cascades of checks. Familiar?
Concat provides a solution!
It's key features are:
Pretty easy, huh?
- Null- and empty string safe
- Clear chaining syntax
String result =
concat.strings('Apex', 'can', 'be').add('less').add('').
add(null).add('painful').with('-').end('!');
Pretty easy, huh?