int (String s, int bracePos) { int braceCount = 1; for(int pos=bracePos+1; pos < s.length(); pos++) { char c = s.charAt(pos); if (c == '{') braceCount++; else if (c == '}') { braceCount--; if (braceCount == 0) return pos; } } return -1; }