Methods for List Class

The table lists the methods for the List class.

List Class

Method Return Value Description
add(Object element)
Boolean Adds the specified element to the end of the list. If the element already exists on the list, an exception is thrown.
add(Integer Index, Object element)
Void Inserts the element at the specified index. If the element already exists on the list or if the index is out of range, an exception is thrown.
addAll(List additions)
Void Appends all the elements in the specified list to the end of the list.
clear()
Void Removes all the elements from the list.
contains(Object element)
Boolean Returns true if the specified element is part of the list, and false otherwise.
get(Integer index)
Object Returns the element at the given index.
isEmpty()
Boolean Returns true if there are no elements in the list, and false otherwise.
iterator()
Iterator Returns an iterator over the elements in the list in proper sequence. This can be used to iterate over the items of the given list. The API methods supported by the Iterator class are listed in the table Logger Class .
remove(Integer index)
Boolean Removes the element at the specified index from the list. If the index is out of range, an exception is thrown.
remove(Object element)
Boolean Removes the first occurrence of the specified element from the list, if it is present.
set(Integer index, Object element)
Object Replaces the element at the specified index in the list with the new specified element. If the index is out of range, an exception is thrown.
size()
Integer Returns the number of elements in the list.
subList(Integer fromIndex,Integer toIndex)
List Returns a list over a subset (between the specified fromIndex, inclusive, and toIndex, exclusive) of items from the original list. The sublist is backed by the original list, so changes to the sublist is reflected in the original list and vice-versa until the original list is structurally modified.