How do you declare a list in apex?
To declare a list, use the List keyword followed by the primitive data, sObject, nested list, map, or set type within <> characters. For example: To access elements in a list, use the List methods provided by Apex.
Which is an example of an instance method in apex?
All are instance methods. Adds an element to the end of the list. Inserts an element into the list at the specified index position. Adds all of the elements in the specified list to the list that calls the method. Both lists must be of the same type. Add all of the elements in specified set to the list that calls the method.
What is the index of a list in apex?
List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. This table is a visual representation of a list of Strings: The index position of the first element in a list is always 0.
How does the equals method work in apex?
Apex uses this method to determine equality and uniqueness for your objects. For more information on providing an equals method, see Using Custom Types in Map Keys and Sets. If the list contains String elements, the elements are case-sensitive. Two list elements that differ only by case are considered distinct.
What are the types of collections in apex?
A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types.
How does a list grow in Salesforce apex?
Even though the size of the previous String array is defined as one element (the number between the brackets in new String[1] ), lists are elastic and can grow as needed provided that you use the List add method to add new elements. For example, you can add two or more elements to the colors list.