Java String Index Of indexOfClosingBracket(String text, int openingBracket)

Here you can find the source of indexOfClosingBracket(String text, int openingBracket)

Description

index Of Closing Bracket

License

Open Source License

Declaration

private static int indexOfClosingBracket(String text, int openingBracket) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.*;

public class Main {
    private static int indexOfClosingBracket(String text, int openingBracket) {
        int result = -1;
        ArrayDeque<String> stack = new ArrayDeque<>();
        for (int i = openingBracket; i < text.length(); i++) {
            if (text.charAt(i) == '(') {
                stack.push("(");
            } else if (text.charAt(i) == ')') {
                if (stack.isEmpty()) {
                    break;
                }/*w  ww.j a va2s .c o  m*/
                stack.pop();
                if (stack.isEmpty()) {
                    result = i;
                    break;
                }
            }
        }
        return result;
    }
}

Related

  1. getReplaceIndexes(String input, int startIndex, Stack replaceStack)
  2. getStructValue(String struct, int index)
  3. getTabIndexes(String text)
  4. getUserGroupsFromImpex( final String impexContent, final int uidIndex)
  5. indexOf(final String str, final String searchString)
  6. indexOfIgnoreCase(final String src, char c, int startIndex, int endIndex)
  7. indexOfIgnoreCase(String str, String substring)
  8. indexOfMultiple(String line, char character, int count, int startIndex)
  9. indexOfWord(String word, String string)