public class StringStack extends Object
String stack with type specific access methods. This
implementation is unsynchronized in order to provide the best possible
performance for typical usage scenarios, so explicit synchronization must
be implemented by a wrapper class or directly by the application in cases
where instances are modified in a multithreaded environment.| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_SIZE
Default initial array size.
|
| Constructor and Description |
|---|
StringStack()
Default constructor.
|
StringStack(int size)
Constructor with initial size specified.
|
StringStack(int size,
int growth)
Constructor with full specification.
|
StringStack(String[] strings)
Constructor from array of strings.
|
StringStack(StringStack base)
Copy (clone) constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Set the stack to the empty state.
|
Object |
clone()
Duplicates the object with the generic call.
|
void |
ensureCapacity(int min)
Ensure that the array has the capacity for at least the specified
number of values.
|
boolean |
isEmpty()
Check if stack is empty.
|
String |
peek()
Copy top value from the stack.
|
String |
peek(int depth)
Copy a value from the stack.
|
String |
pop()
Pop a value from the stack.
|
String |
pop(int count)
Pop multiple values from the stack.
|
void |
push(String value)
Push a value on the stack.
|
int |
size()
Get the number of values currently present in the stack.
|
String[] |
toArray()
Constructs and returns a simple array containing the same data as held
in this stack.
|
public static final int DEFAULT_SIZE
public StringStack(int size,
int growth)
size - number of String values initially allowed in
stackgrowth - maximum size increment for growing stackpublic StringStack(int size)
size - number of String values initially allowed in
stackpublic StringStack()
public StringStack(StringStack base)
base - instance being copiedpublic StringStack(String[] strings)
strings - array of strings for initial contentspublic final void ensureCapacity(int min)
min - minimum capacity to be guaranteedpublic void push(String value)
value - value to be addedpublic String pop()
ArrayIndexOutOfBoundsException - on attempt to pop empty stackpublic String pop(int count)
count - number of values to pop from stack (must be strictly
positive)ArrayIndexOutOfBoundsException - on attempt to pop past end of
stackpublic String peek(int depth)
depth - depth of value to be returnedArrayIndexOutOfBoundsException - on attempt to peek past end of
stackpublic String peek()
ArrayIndexOutOfBoundsException - on attempt to peek empty stackpublic String[] toArray()
public Object clone()
public int size()
public boolean isEmpty()
true if stack empty, false if notpublic void clear()
Copyright © 2005–2016 jibx.org. All rights reserved.