Java Utililty Methods Stack Usage

List of utility methods to do Stack Usage

Description

The list of methods to do Stack Usage are organized into topic(s).

Method

booleanendsWithIgnoreWhiteSpace(String decl, String token)
ends With Ignore White Space
int index = decl.length() - 1;
Stack<Character> stack = new Stack<Character>();
for (int i = 0; i < token.length(); index--) {
    if (decl.charAt(index) == ' ' || decl.charAt(index) == '\t')
        continue;
    char c = decl.charAt(index);
    stack.push(c);
    i++;
...
StackgetBinary(long input)
get Binary
Stack<Integer> binaryStack = new Stack<Integer>();
while (input != 0) {
    binaryStack.push((int) input % 2);
    input = input / 2;
return binaryStack;
String[]getOperands(Stack stack, int nOperands)
get Operands
String[] operands = new String[nOperands];
for (int j = nOperands - 1; j >= 0; j--) {
    if (stack.isEmpty()) {
        String msg = "Too few arguments supplied to operation. Expected (%d) operands but got (%d)!";
        msg = String.format(msg, nOperands, nOperands - j - 1);
        throw new IllegalStateException(msg);
    operands[j] = stack.pop();
...
voidgetPermutationsRec(List permutations, byte[] order, List> remaining, int index)
get Permutations Rec
if (order[order.length - 1] != 0) {
    permutations.add(order.clone());
for (Stack<Byte> stack : remaining) {
    if (stack.empty()) {
    } else {
        order[index] = stack.pop();
        getPermutationsRec(permutations, order, remaining, index + 1);
...
ListgetPostOrder(List inOrderList)
get Post Order
List<String> result = new ArrayList<>();
Stack<String> stack = new Stack<>();
for (int i = 0; i < inOrderList.size(); i++) {
    if (Character.isDigit(inOrderList.get(i).charAt(0))) {
        result.add(inOrderList.get(i));
    } else {
        switch (inOrderList.get(i).charAt(0)) {
        case '(':
...
StringgetRelativePath(Stack pathStack)
get Relative Path
StringBuilder sb = new StringBuilder();
sb.append('/');
int size = pathStack.size();
for (int i = 0; i < size; i++) {
    sb.append(pathStack.get(i)).append('/');
return sb.toString();
String[]getSyllables(String pinyin)
Breaks a pinyin string on tone markers
List syllables = new ArrayList();
Stack last = new Stack();
Stack next = new Stack();
for (int i = pinyin.length() - 1; i >= 0; i--) {
    next.push(new Character(pinyin.charAt(i)));
do {
    char c = ((Character) next.pop()).charValue();
...
booleanisDoubleQuote(Stack bufStack)
Check whether the peek of the stack element is double quote.
if (!bufStack.isEmpty() && bufStack.peek() == '"') {
    return true;
return false;
StringnormalizeAbsolutePath(String curDir)
Given an absolute path (starting with '/'), normalize it so that there are no ".."
if (curDir == null) {
    return null;
StringBuffer buf = new StringBuffer(curDir);
int maxIndex = buf.length();
int thisIndex = buf.indexOf("/");
Stack<Integer> slashStack = new Stack<Integer>();
while ((thisIndex != -1) && (thisIndex != maxIndex)) {
...
StringremoveBackets(String cont)
remove Backets
if (cont == null)
    return null;
int len = cont.length();
Stack<Character> stack = new Stack<Character>();
char c;
for (int i = 0; i < len; i++) {
    c = cont.charAt(i);
    if (c == ')') {
...