public String next(Pattern pattern){
  checkOpen();
  checkNotNull(pattern);
  matchSuccessful=false;
  saveCurrentStatus();
  if (!setTokenRegion()) {
    recoverPreviousStatus();
    throw new NoSuchElementException();
  }
  matcher.usePattern(pattern);
  if (!matcher.matches()) {
    recoverPreviousStatus();
    throw new InputMismatchException();
  }
  matchSuccessful=true;
  return matcher.group();
}

public String next ( Pattern pattern ) { checkOpen ( ) ; checkNotNull ( pattern ) ; matchSuccessful = false ; saveCurrentStatus ( ) ; if ( ! setTokenRegion ( ) ) { recoverPreviousStatus ( ) ; throw new NoSuchElementException ( ) ; } matcher . usePattern ( pattern ) ; if ( ! matcher . matches ( ) ) { recoverPreviousStatus ( ) ; throw new InputMismatchException ( ) ; } matchSuccessful = true ; return matcher . group ( ) ; }
returns the next token if it matches the specified pattern . the token will be both prefixed and suffixed by the delimiter that is currently being used ( or a string that matches the delimiter pattern ) . this method will block if input is being read .
