Apex Methods for List, Map, and String
with Explanations
List Methods in Apex
add(item): Adds an element to the end of the list.
add(index, item): Adds an element at a specific index.
addAll(list): Adds all elements from another list.
clear(): Removes all elements.
contains(item): Checks if an item exists.
deepClone(): Creates a deep copy.
equals(list): Compares for equality.
get(index): Retrieves the element at a given index.
indexOf(item): Finds the index of an item.
isEmpty(): Returns true if the list is empty.
remove(index): Removes the element at the index.
set(index, item): Replaces an item at the index.
size(): Returns number of elements.
sort(): Sorts list in ascending order.
Map Methods in Apex
clear(): Removes all key-value pairs.
clone(): Makes a shallow copy.
containsKey(key): Checks if key exists.
deepClone(): Makes a deep copy.
equals(map): Compares two maps.
get(key): Gets value by key.
isEmpty(): Returns true if map is empty.
keySet(): Returns all keys.
put(key, value): Adds a key-value pair.
putAll(map): Adds all pairs from another map.
remove(key): Deletes a key-value pair.
size(): Returns number of entries.
values(): Gets all values.
String Methods in Apex
charAt(index): Character at the position.
compareTo(string): Lexicographical comparison.
concat(string): Joins two strings.
contains(string): Checks if substring exists.
endsWith(string): Checks if string ends with substring.
equals(string): Checks equality.
format(template, values): Formats string using template.
indexOf(string): First index of substring.
isEmpty(): Checks if string is empty.
lastIndexOf(string): Last index of substring.
length(): Length of string.
replace(old, new): Replace substring.
split(delimiter): Splits string.
startsWith(string): Checks if starts with substring.
substring(start, end): Extract substring.
toLowerCase(): Converts to lowercase.
toUpperCase(): Converts to uppercase.
trim(): Removes surrounding spaces.