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
Kalpana WankhedeKalpana Wankhede 

Can we predefined length of the list?

Best Answer chosen by Kalpana Wankhede
mukesh guptamukesh gupta
Hi Kalpana,

Please  follow below code:-
 
List<String> colors = new String[1];
 
String[] colors = new String[1];
 
List<Integer> ints = new Integer[6];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 

All Answers

AnkaiahAnkaiah (Salesforce Developers) 
Hi Kalpana,

Yes, you can predefined length of the list.

ex:
//Defines an Integer list with memory allocated for six Integers
List<Integer> ints = new Integer[6]; 

Refer the below help article.

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_collections_lists.htm

if this helps, Please mark it as best answer.

Thanks!!

 
mukesh guptamukesh gupta
Hi Kalpana,

Please  follow below code:-
 
List<String> colors = new String[1];
 
String[] colors = new String[1];
 
List<Integer> ints = new Integer[6];

if you need any assistanse, Please let me know!!

Kindly mark my solution as the best answer if it helps you.

Thanks
Mukesh 
This was selected as the best answer