public class ArrayListOfLongs extends Object implements RandomAccess, Cloneable, Iterable<Long>
| Modifier and Type | Field and Description |
|---|---|
protected long[] |
array |
protected int |
size |
| Constructor and Description |
|---|
ArrayListOfLongs()
Constructs an empty list with an initial capacity of ten.
|
ArrayListOfLongs(int initialCapacity)
Constructs an empty list with the specified initial capacity.
|
ArrayListOfLongs(int first,
int last)
Constructs a list populated with longs in range [first, last).
|
ArrayListOfLongs(long[] a)
Constructs a list from an array.
|
| Modifier and Type | Method and Description |
|---|---|
ArrayListOfLongs |
add(int index,
long element)
Inserts the specified element at the specified position in this list.
|
ArrayListOfLongs |
add(long e)
Appends the specified element to the end of this list.
|
void |
addUnique(long[] arr)
Add all longs in the specified array into this list, ignoring duplicates.
|
void |
clear()
Removes all of the elements from this list.
|
ArrayListOfLongs |
clone()
Returns a clone of this object.
|
boolean |
contains(long n)
Returns true if this list contains the specified element.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this object, if necessary, to ensure that it can hold at least the
number of elements specified by the minimum capacity argument.
|
boolean |
equals(Object obj)
Elementwise comparison.
|
long |
get(int index)
Returns the element at the specified position in this list.
|
long[] |
getArray()
Returns the array backing this object.
|
int |
indexOf(long n)
Returns the index of the first occurrence of the specified element in this list, or -1 if this
list does not contain the element.
|
ArrayListOfLongs |
intersection(ArrayListOfLongs other)
Computes the intersection of two sorted lists of unique longs.
|
boolean |
isEmpty()
Returns true if this list contains no elements.
|
Iterator<Long> |
iterator()
Returns an iterator for this list.
|
int |
lastIndexOf(long n)
Returns the index of the last occurrence of the specified element in this list, or -1 if this
list does not contain the element.
|
ArrayListOfLongs |
merge(ArrayListOfLongs sortedLst)
Merges two sorted (ascending order) lists into one sorted union.
|
long |
remove(int index)
Removes the element at the specified position in this list.
|
long |
set(int index,
long element)
Replaces the element at the specified position in this list with the specified element.
|
void |
setSize(int sz)
Specifies the length of this list.
|
void |
shiftLastNToTop(int n) |
int |
size()
Returns the number of elements in this list.
|
void |
sort()
Sorts this list.
|
ArrayListOfLongs |
subList(int start,
int end)
Extracts a sub-list.
|
String |
toString() |
String |
toString(int n)
Returns a string representation of the object, explicitly printing out the first n
elements of this list.
|
void |
trimToSize()
Trims the capacity of this object to be the list's current size.
|
public ArrayListOfLongs(int initialCapacity)
initialCapacity - the initial capacity of the listIllegalArgumentException - if the specified initial capacity is negativepublic ArrayListOfLongs()
public ArrayListOfLongs(long[] a)
a - source arraypublic ArrayListOfLongs(int first,
int last)
first - the smallest element in the range (inclusive)last - the largest element in the range (exclusive)public void trimToSize()
public void ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacitypublic int size()
public void setSize(int sz)
public boolean isEmpty()
public boolean contains(long n)
n - element whose presence in this list is to be testedpublic int indexOf(long n)
public int lastIndexOf(long n)
public ArrayListOfLongs clone()
public long get(int index)
index - index of the element to returnpublic long set(int index,
long element)
index - index of the element to replaceelement - element to be stored at the specified positionpublic ArrayListOfLongs add(long e)
public ArrayListOfLongs add(int index, long element)
index - index at which the specified element is to be insertedelement - element to be insertedpublic long remove(int index)
index - the index of the element to be removedpublic void clear()
public long[] getArray()
public Iterator<Long> iterator()
Iterable interface; this method is not efficient because of
autoboxing.public String toString(int n)
public void sort()
public ArrayListOfLongs intersection(ArrayListOfLongs other)
other - other list to be intersected with this listpublic ArrayListOfLongs merge(ArrayListOfLongs sortedLst)
sortedLst - list to be merged into thispublic ArrayListOfLongs subList(int start, int end)
start - first index to be included in sub-listend - last index to be included in sub-liststart to endpublic void addUnique(long[] arr)
arr - array of longs to add to this objectpublic void shiftLastNToTop(int n)
Copyright © 2014. All rights reserved.