K
- when you use the enough-polish-client-java5.jar you can parameterize the ArrayList, e.g. ArrayList<Integer> = new ArrayList<Integer>(10);public class ArrayList extends Object
Provides an flexible list for storing objects.
This ArrayList is mostly compatible with the java.util.ArrayList of the J2SE. It lacks, however, some not often used methods. Also some methods like add or remove do not return a boolean value, since true is always returned (or an exception is thrown) anyhow. This way we can save some precious space!
Workarounds for some of the missing methods:
Constructor and Description |
---|
ArrayList()
Creates an ArrayList with the initial capacity of 10 and a growth factor of 75%
|
ArrayList(int initialCapacity)
creates an ArrayList with the given initial capacity and a growth factor of 75%
|
ArrayList(int initialCapacity,
int growthFactor)
Creates a new ArrayList
|
Modifier and Type | Method and Description |
---|---|
void |
add(int index,
Object element)
Inserts the given element at the defined position.
|
void |
add(Object element)
Stores the given element in this list.
|
void |
clear()
Removes all of the elements from this list.
|
boolean |
contains(Object element)
Determines whether the given element is stored in this list.
|
Object |
get(int index)
Returns the element at the specified position in this list.
|
Object[] |
getInternalArray()
Retrieves the internal array - use with care!
This method allows to access stored objects without creating an intermediate
array.
|
int |
indexOf(Object element)
Retrieves the index of the given object.
|
Object |
remove(int index)
Removes the element at the specified position in this list.
|
boolean |
remove(Object element)
Removes the given element.
|
Object |
set(int index,
Object element)
Replaces the element at the specified position in this list with the specified element.
|
int |
size()
Retrieves the current size of this array list.
|
Object[] |
toArray()
Returns all stored elements as an array.
|
Object[] |
toArray(Object[] target)
Returns all stored elements in the given array.
|
String |
toString()
Returns String containing the String representations of all objects of this list.
|
void |
trimToSize()
Trims the capacity of this ArrayList instance to be the list's current size.
|
public ArrayList()
public ArrayList(int initialCapacity)
initialCapacity
- the capacity of this array list.public ArrayList(int initialCapacity, int growthFactor)
initialCapacity
- the capacity of this array list.growthFactor
- the factor in % for increasing the capacity
when there's not enough room in this list anymorepublic int size()
public boolean contains(Object element)
element
- the element which might be stored in this listIllegalArgumentException
- when the given element is nullremove(Object)
public int indexOf(Object element)
element
- the object which is part of this list.IllegalArgumentException
- when the given element is nullpublic Object get(int index)
index
- the position of the desired element.IndexOutOfBoundsException
- when the index < 0 || index >= size()public Object remove(int index)
index
- the position of the desired element.IndexOutOfBoundsException
- when the index < 0 || index >= size()public boolean remove(Object element)
element
- the element which should be removed.IllegalArgumentException
- when the given element is nullcontains(Object)
public void clear()
public void add(Object element)
element
- the element which should be appended to this list.IllegalArgumentException
- when the given element is nulladd( int, Object )
public void add(int index, Object element)
index
- the position at which the element should be inserted,
use 0 when the element should be inserted in the front of this list.element
- the element which should be insertedIllegalArgumentException
- when the given element is nullIndexOutOfBoundsException
- when the index < 0 || index >= size()public Object set(int index, Object element)
index
- the position of the element, the first element has the index 0.element
- the element which should be setIndexOutOfBoundsException
- when the index < 0 || index >= size()public String toString()
public Object[] toArray()
public Object[] toArray(Object[] target)
target
- the array in which the stored elements should be copied.public void trimToSize()
public Object[] getInternalArray()