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
Camilo Andres Torres PatiñoCamilo Andres Torres Patiño 

I need help with Unexpected token '='.

Hi, I was programming a class but when I executed the code, it appeared an error saying: Line: 2, Column: 7, Unexpected token '='. Somebody could tell me why this error is pop-upping and how to solve it?

Here is my code:
code
ANUTEJANUTEJ (Salesforce Developers) 
Hi Camilo,

Can you try to use the add function present for the list class instead of assigning to the list individually.

you can check the below snippet of code once:

 public static List<String> generateStringArray(Integer n)
    {
        List<String> List1 = new List<String>();
        for(Integer i =0; i < n; ++i)
            List1.add('Test ' + i);
        return List1;
    }

This worked for me let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
RituSharmaRituSharma
Replace below line:
FormattedStrings[n] = 'Test ' + String.valueOf(n);

With:
FormattedStrings.add('Test ' + n);