static int firstIllegalCharacter(String source){
  for (int i=0; i < source.length(); i++) {
    if (isLegal(source.charAt(i)) == false) {
      return i;
    }
  }
  return -1;
}

static int firstIllegalCharacter ( String source ) { for ( int i = 0 ; i < source . length ( ) ; i ++ ) { if ( isLegal ( source . charAt ( i ) ) == false ) { return i ; } } return - 1 ; }
utility method to find the first invalid character as per rfc 2396 section 2 . this helps us prevent creating excessive objects in the encode ( ) methods since most strings will not be encoded .
