Interface List<T>
-
public interface List<T>
A slightly-simplified version of Java'sList
interface. Represents an indexed, growable list of generic objects.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
add(int index, T data)
Insert a new element into the list and move later elements up by one index.T
get(int index)
Return the element at the index in the list.void
remove(int index)
Remove the element at the given index and move later elements down by one.void
set(int index, T data)
Set the value of the element at an existing, legal index to something new.int
size()
Return the number of elements in the list.
-
-
-
Method Detail
-
get
T get(int index) throws java.lang.IndexOutOfBoundsException
Return the element at the index in the list. If the list currently has k elements, the only valid indices are 0 through k-1, regardless of its capacity; any other index should be an IndexOutOfBoundsException.- Parameters:
index
- the index to get- Returns:
- the value of the element at the index
- Throws:
java.lang.IndexOutOfBoundsException
-
set
void set(int index, T data) throws java.lang.IndexOutOfBoundsException
Set the value of the element at an existing, legal index to something new. If the list currently has k elements, the only valid indices are 0 through k-1, regardless of its capacity; any other index should result in an IndexOutOfBoundsException.- Parameters:
index
- the index to alterdata
- the value to assign at that index- Throws:
java.lang.IndexOutOfBoundsException
-
add
void add(int index, T data) throws java.lang.IndexOutOfBoundsException, java.lang.IllegalStateException
Insert a new element into the list and move later elements up by one index. If a list consists of [ A B C ], and add(1,D) is called, it should newly be [ A D B C ]. If there are k elements in the list, legal indices are 0-k. All others should result in IndexOutOfBoundsException. Also, performing an add when it would result in outgrowing the capacity should result in an IllegalStateException.- Parameters:
index
- the index where the new element will godata
- the value to insert at that index- Throws:
java.lang.IndexOutOfBoundsException
java.lang.IllegalStateException
-
remove
void remove(int index) throws java.lang.IndexOutOfBoundsException
Remove the element at the given index and move later elements down by one. If a list consists of [ A B C D ], and remove(1) is called, this should return B, and result in [ A C D ]. If you try and remove something at a bad index, it should throw a IndexOutOfBoundsException.- Parameters:
index
- the index to remove from- Throws:
java.lang.IndexOutOfBoundsException
-
size
int size()
Return the number of elements in the list. Note this is NOT the same as the capacity of the underlying array storage.- Returns:
- the number of elements currently in the list
-
-