In Apex code how do we convert string to array. Java toCharArray does not work.
String string = 'somestring' to [s, o, m, e ...]
You can use the String.split() method, using ''
(two single quotes) as a parameter::
String ourString = 'Salesforce SE';
String[] stringCharacters = ourString.split('');
System.debug(stringCharacters);
// stringCharacters is a List<String>, each element being a substring of length 1:
// (,S,a,l,e,s,f,o,r,c,e, ,S,E)
Note that in API version 34.0 and earlier,the first element in the collection will be "empty":
String firstElement = stringCharacters.remove(0);
System.debug(stringCharacters);
// (S,a,l,e,s,f,o,r,c,e, ,S,E)