java.lang.Cloneable
ListStack
public class List
extends java.lang.Object
implements java.lang.Cloneable
List
,
Collection
Constructor | Description |
---|---|
List() |
Creates a new BasicSet with the default Size
|
List(int size) |
Modifier and Type | Method | Description |
---|---|---|
boolean |
add(int index,
java.lang.Object obj) |
Adds the specified Object to the list at the specified index
|
boolean |
add(java.lang.Object obj) |
Adds the specified Object to the list
|
void |
clear() |
Removes all elements from the list
|
java.lang.Object |
clone() |
|
boolean |
contains(java.lang.Object obj) |
Returns true if the specified element is contained in the list.
|
boolean |
equals(java.lang.Object obj) |
Compares the specified object with this list for equality.
|
java.lang.Object |
get(int index) |
Returns the element at the specified position in this list.
|
int |
hashCode() |
As defined by the JDK 1.2 API spec:
Returns the hash code value for this list. |
int |
indexOf(java.lang.Object obj) |
Returns the index of the first occurrence of the specified element,
or -1 if the element is not contained in the List
|
boolean |
isEmpty() |
Returns true if there are no elements in the List.
|
int |
lastIndexOf(java.lang.Object obj) |
Returns the index of the last occurrence of the specified element,
or -1 if the element is not contained in the List
|
java.lang.Object |
remove(int index) |
Removes the element at the specified index from the List
|
boolean |
remove(java.lang.Object obj) |
Removes the first occurrence of the specified element from the List
|
java.lang.Object |
set(int index,
java.lang.Object element) |
Replaces the element at the specified position in this list
with the specified element.
|
int |
size() |
Returns the number of elements in the List
|
List |
subList(int fromIndex,
int toIndex) |
Returns a new List which contains elements from a given section
of this list.
|
java.lang.Object[] |
toArray() |
Returns an array containing all of the elements in this list
in proper sequence.
|
java.lang.Object[] |
toArray(java.lang.Object[] dst) |
Returns an array containing all of the elements in this list
in proper sequence.
|
void |
trimToSize() |
Reduces the capacity of the internal buffer to the current size
freeing up unused memory.
|
public List()
public List(int size)
public boolean add(java.lang.Object obj)
obj
- the Object to add to the listpublic boolean add(int index, java.lang.Object obj) throws java.lang.IndexOutOfBoundsException
obj
- the Object to add to the listjava.lang.IndexOutOfBoundsException
public void clear()
public java.lang.Object clone()
public boolean contains(java.lang.Object obj)
obj
- the element to search the list forpublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public java.lang.Object get(int index) throws java.lang.IndexOutOfBoundsException
index
- the position of the element to returnjava.lang.IndexOutOfBoundsException
public int hashCode()
hashCode = 1;
Iterator i = list.iterator();
while (i.hasNext()) {
Object obj = i.next();
hashCode = 31*hashCode + (obj==null ? 0 : obj.hashCode());
}
hashCode
in class java.lang.Object
public int indexOf(java.lang.Object obj)
obj
- the Object to get the index forpublic boolean isEmpty()
public int lastIndexOf(java.lang.Object obj)
obj
- the Object to get the last index forpublic java.lang.Object remove(int index)
index
- the position in the list tp remove the element frompublic boolean remove(java.lang.Object obj)
obj
- the Object to remove from the Listpublic void trimToSize()
public java.lang.Object set(int index, java.lang.Object element) throws java.lang.IndexOutOfBoundsException
index
- the position in the list to place the element atelement
- the element to add to the listjava.lang.IndexOutOfBoundsException
public int size()
public List subList(int fromIndex, int toIndex)
fromIndex
- the start index (inclusize) of elements
to add to the new listtoIndex
- the end index (exclusive)of the elements to add
to the new listjava.lang.IndexOutOfBoundsException
- for invalid index valuespublic java.lang.Object[] toArray()
public java.lang.Object[] toArray(java.lang.Object[] dst)