[SalesForce] String Split method

Apex String split() results an empty list item even there is no value.

For example,

String test = '';
list<string> test1 = test.split(',');
System.debug(test1.size());    // Result = 1

so I had my own method to omit empty list items. Is there a better function to do splitting and to omit empty ones.

Appreciate any help on this. Thanks.

Best Answer

Your value is an empty string. There is nothing to split that matches your criteria which means the whole string (empty string) will be the result and it will be placed at the first index in the result array... '' is still a value at the end of the day

Related Topic