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.

2 Answers 2


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


Hi You can add if condition before spliting

String test = '';

      list<string> test1 = test.split(',');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .