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
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
- duplicates
-
JDK-6245365 Missing Closing Parenthesis in java.util.Scanner code snippet
-
- Resolved
-