function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
fiona gentryfiona gentry 

Expression must be a list type: String IN Apex class

Dear folks,

I wrote this code to  Return an array of characters in reversed order for alphanumeric characters ,but i keep getting error as

Expression must be a list type: String
 
public class assessment {
 public static List<String> reverseAlphaNumericCharacters(String s) {
    List<String> reversedChars = new List<String>();
    for (Integer i = s.length() - 1; i >= 0; i--) {
        if (isAlphaNumeric(s[i])) {
            reversedChars.add(s[i]);
        }
    }
    return reversedChars;
}

private static Boolean isAlphaNumeric(String c) {
    return ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z') || ('0' <= c && c <= '9');
}

}

Kindly let me know what wrong am doing?

Thanks
Tarun

 
AnkaiahAnkaiah (Salesforce Developers) 
Hi Fiona,

Refer the below link have solution for similar kind of ask.
https://salesforce.stackexchange.com/questions/392234/how-to-resolve-expression-must-be-a-list-type-string-in-apex-class

Thanks!!