T - type of elements in the arraypublic class SimpleArray<T> extends Object implements Iterable<T>
This class is useful in a few cases:
| Constructor and Description |
|---|
SimpleArray(T[] initial)
Create an instance backed by an array.
|
SimpleArray(T[] initial,
int size)
Create an instance backed by an array with a specified number of preallocated elements.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(T element)
Add an element to the end of the list.
|
void |
addAll(T[] src)
Add all elements from an array.
|
protected int |
calculateNewCapacity(int currentCapacity) |
void |
clear()
Clear all elements.
|
void |
copyTo(T[] dst,
int offset)
Copy all elements from the backing array to another array.
|
T[] |
elements()
Get an array with all elements.
|
T |
get(int index)
Get the element at the specified index.
|
Iterator<T> |
iterator() |
int |
size()
Get the number of stored elements.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic SimpleArray(T[] initial)
initial - array to use for storagepublic SimpleArray(T[] initial, int size)
initial - array to use for storagesize - number of preallocated elementspublic T get(int index)
index - element indexpublic void add(T element)
element - element to addpublic void addAll(T[] src)
src - array containing elements to addpublic void copyTo(T[] dst, int offset)
dst - array to copy elements tooffset - starting position in the destination arrayprotected int calculateNewCapacity(int currentCapacity)
public int size()
public void clear()
public T[] elements()
Copyright © 2019. All rights reserved.