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 Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It only takes a minute to sign up.
Sign up to join this communitySalesforce 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(',');
System.debug(lstAlpha);
@Nebula - because pipe (|) is a regex symbol, using following code splits the string properly
String alpha = 'split | this | sentence';
List<String> lstAlpha = alpha.split('\\|');