Experience Salesforce

List Array Notation in APEX

What You’ll Learn

  • What Is List Array Notation?

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 Extra Support? Our FREE study materials have got you covered.

Our expert-prepared study materials provide the answers you need. Clear your doubts and improve your skills with detailed notes from industry professionals.

cts-img
Rakshabandhan Sale