Learn from industry experts! Admin batch starts from 19 Feb.
Hurry up!
Book your slot now!

3

List Array Notation in APEX

List Array Notation in APEX

Array notation is a notation where a list’s elements are referenced by enclosing the index number in square brackets after the list’s name. Developers comfortable with Array notation can also use it while using Lists. Array and List syntax are often used interchangeably.

When using one-dimensional lists of primitives or objects, you can also use more traditional array notation to declare and reference list elements. For example, you can declare a one-dimensional list of primitives or objects by following the data type name with the [] characters.

Syntax Of List Array Notation

String[] nameList = new String[4];
//or
String[] nameList2 = new List();
//or
List nameList3 = new String[4];
// Set values for 0, 1, 2 indices
nameList[0] = 'Bhavna';
nameList[1] = 'Bhavya';
nameList[2] = 'Swati';
// Size of the list, which is always an integer value
Integer listSize = nameList.size();
// Accessing the 2nd element in the list, denoted by index 1 System.debug(nameList[1]); // ‘Bhavna’
Salesforce Developer
Next Topic

Need more support?

Get a head start with our FREE study notes!

Learn more and get all the answers you need at zero cost. Improve your skills using our detailed notes prepared by industry experts to help you excel.

Book A 15-Minutes Free Career Counselling Today!