Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6207991

Parenthesis missing in code example in Scanner.java javadoc.

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 5.0
    • core-libs

      A DESCRIPTION OF THE PROBLEM :
      Parenthesis missing in code example in Scanner.java javadoc.

      In the javadoc, the following line appears:
      System.out.println(result.group(i);
      It should be:
      System.out.println(result.group(i));

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The same output can be generated with this code, which uses a regular expression to parse all four tokens at once:

           String input = "1 fish 2 fish red fish blue fish";
           Scanner s = new Scanner(input);
           s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
           MatchResult result = s.match();
           for (int i=1; i<=result.groupCount(); i++)
               System.out.println(result.group(i));
           s.close();
      ACTUAL -
      The same output can be generated with this code, which uses a regular expression to parse all four tokens at once:

           String input = "1 fish 2 fish red fish blue fish";
           Scanner s = new Scanner(input);
           s.findInLine("(\\d+) fish (\\d+) fish (\\w+) fish (\\w+)");
           MatchResult result = s.match();
           for (int i=1; i<=result.groupCount(); i++)
               System.out.println(result.group(i);
           s.close();

      URL OF FAULTY DOCUMENTATION :
      http://java.sun.com/j2se/1.5.0/docs/api/java/util/Scanner.html
      ###@###.### 2004-12-14 01:00:33 GMT

            martin Martin Buchholz
            gmanwanisunw Girish Manwani (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: