Call: IN +91 7013283324 | +91 9347854179
(Click on WhatsApp Chat button)
Call: US +1 (415) 529-7271

Salesforce Apex Tutorial – Chapter 7: Apex Arrays

Home  >>  Salesforce Apex Tutorial  >>  Salesforce Apex Tutorial – Chapter 7: Apex Arrays

Salesforce Apex Tutorial – Chapter 7: Apex Arrays

On October 8, 2021, Posted by , In Salesforce Apex Tutorial, With Comments Off on Salesforce Apex Tutorial – Chapter 7: Apex Arrays
Salesforce Apex Tutorial – Chapter 7 - Apex Arrays
Salesforce Apex Tutorial – Chapter 7 – Apex Arrays

Arrays in the apex are collections of similar elements, where the memory is allocated sequentially. Each element in the array is located by index and the index value starts with zero. An array in Apex is basically the same as the list in Apex.

In Apex, there are two ways to declare an array.

  1. Static Declaration

Syntax:  DataType arrayname = new DataType[] {value 1, value 2};

For example,

  • Integer[] marks =new Integer[] {1,2,3};
  • String[] s1 = new String[] {‘abc’,’def’,’ghi’}; 
  1. Dynamic Declaration

Syntax:  DataType[] arrayname = new DataType[size];

For example,

  • String s1 = new String[2];
    s1[0] =’Salesforce’;
    s1[1] =force;

Integer a1 = new Integer[2];
a1[0] = 5;
a2[1] = 10;

Comments are closed.