Apex – Convert comma-separated String to a List

How to convert below String into List<String> in Apex Programming ?

String alpha = 'A, B, C, D';

In java, its very easy like below:

List<String> result = Arrays.asList(alpha.split("\\s*,\\s*"));


Salesforce provide String class which can be used to work with string. In your case you can use Split method

String alpha = 'A, B, C, D';

List<String> lstAlpha = alpha.split(',');


Source : Link , Question Author : user4567570 , Answer Author : Himanshu

Leave a Comment