public static int findNonNestedChar(final String haystack,final String needles){
  int openBrackets=0;
  for (int i=0; i < haystack.length(); i++) {
    if (haystack.charAt(i) == '(' || haystack.charAt(i) == '[' || haystack.charAt(i) == '{') {
      openBrackets++;
    }
 else     if (haystack.charAt(i) == ')' || haystack.charAt(i) == ']' || haystack.charAt(i) == '}') {
      openBrackets--;
    }
 else     if (openBrackets == 0) {
      for (int j=0; j < needles.length(); j++) {
        if (haystack.charAt(i) == needles.charAt(j)) {
          return i;
        }
      }
    }
  }
  return -1;
}

public static int findNonNestedChar ( final String haystack , final String needles ) { int openBrackets = 0 ; for ( int i = 0 ; i < haystack . length ( ) ; i ++ ) { if ( haystack . charAt ( i ) == '(' || haystack . charAt ( i ) == '[' || haystack . charAt ( i ) == '{' ) { openBrackets ++ ; } else if ( haystack . charAt ( i ) == ')' || haystack . charAt ( i ) == ']' || haystack . charAt ( i ) == '}' ) { openBrackets -- ; } else if ( openBrackets == 0 ) { for ( int j = 0 ; j < needles . length ( ) ; j ++ ) { if ( haystack . charAt ( i ) == needles . charAt ( j ) ) { return i ; } } } } return - 1 ; }
finds the first index of a needle character in the haystack , that is not nested in brackets .
