I have a requirement to exclude last element from a list. For example if my list is like this:
List<String> str=new List<String>{'2023, 2024, 2025, 2026, 2027'};
I need a new list which will have only till 2026.
If I have a list :
List<String> = new List<String>{'2023, 2024'};
I need a new list which will have only 2023.
I created a new List<string> str1 = new List<string>();
I tried to use the traditional for loop but it seems to be not working.
for(Integer i=0; i< (str.size()-1); i++){
str1.add(str(i));
}
Error: Method does not exist or incorrect signature: void str(Integer) from the type myApexClass
Any way to add the desired output to the new List str1, please suggest.
List<String> str= '2023, 2024, 2025, 2026, 2027';
is not valid syntax.