Class List


  extended by Object
      extended by List

public class List
extends Object

The List class implements a growable array of objects. It contains elements that can be accessed using an integer index. The size of a List can grow or shrink as needed to accommodate adding and removing items after the List has been created.

A List is meant to contain instances of objects found in this api. Primitives, Strings, binary data and constructs of these are to be stored in Value structures.

See Also:
Value

Constructor Summary
List()
          Constructs a new List instance with initial capacity of 10 elements.
 
Method Summary
 List add(int index, Object element)
          Inserts the specified element at the specified position in this list.
 List add(Object element)
          Appends the specified element to the end of this list
 void clear()
          Removes all of the elements from this list.
 int indexOf(Object obj)
          Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.
 int lastIndexOf(Object obj)
          Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.
 Object operator_get(int index)
          An operator that returns the element at the specified position in this list.
 Object operator_set(int index, Object element)
          Replaces the element at the specified position in this list with the specified element.
 Object pop()
          Removes the object at the end of of this list and returns that object as the value of this function.
 void push(Object element)
          Pushes an item onto the end of this list.
 Object remove(int index)
          Removes the element at the specified position in this list.
 int size()
          Returns the number of elements in this list.
 void sort(Comparator comparator)
           Sorts this list according to the order induced by the specified comparator.
 
Methods inherited from class Object
toString, equals, hashCode
 
Methods inherited from
equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

List

public List()
Constructs a new List instance with initial capacity of 10 elements.

Method Detail

size

public int size()
Returns the number of elements in this list.

Returns:
the number of elements in this list.

clear

public void clear()
Removes all of the elements from this list. This list will be empty after this call returns.


add

public List add(int index,
                Object element)
Inserts the specified element at the specified position in this list. Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).

Parameters:
index - index at which the specified element is to be inserted.
element - element to be inserted.
Returns:
this List instance

add

public List add(Object element)
Appends the specified element to the end of this list

Parameters:
element - element to be appended to this list.
Returns:
this List instance

remove

public Object remove(int index)
Removes the element at the specified position in this list. Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.

Parameters:
index - the index of the element to removed.
Returns:
the element previously at the specified position.

indexOf

public int indexOf(Object obj)
Returns the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.

Parameters:
obj - element to search for.
Returns:
the index in this list of the first occurrence of the specified element, or -1 if this list does not contain this element.

lastIndexOf

public int lastIndexOf(Object obj)
Returns the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.

Parameters:
obj - element to search for.
Returns:
the index in this list of the last occurrence of the specified element, or -1 if this list does not contain this element.

pop

public Object pop()
Removes the object at the end of of this list and returns that object as the value of this function.

Returns:
The object at the end of this list

push

public void push(Object element)
Pushes an item onto the end of this list. This has exactly the same effect as:
 add(item)

Parameters:
element - the item to be pushed onto this stack.

operator_get

public Object operator_get(int index)
An operator that returns the element at the specified position in this list.

List list = ...;
Object o = list[i];

Parameters:
index - index of element to return.
Returns:
the element at the specified position in this list.
See Also:
get

operator_set

public Object operator_set(int index,
                           Object element)
Replaces the element at the specified position in this list with the specified element.

List list = ...;
list[i] = "hello";

Parameters:
index - index of element to replace.
element - element to be stored at the specified position.
Returns:
the element
See Also:
set

sort

public void sort(Comparator comparator)

Sorts this list according to the order induced by the specified comparator.

A Comparator callback function is given that will determine the ordering of successive elements.

Parameters:
comparator - The comparator to determine the order of the list.
See Also:
Callbacks