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();
What has confused me is that is the method summary on the same page, it states that findInLine returns a String value. The above example clearly does not return a value into a String. My question is as follows:
Is it the case that because it returns a value that is sub-classed off Object that it imlicitly performs a "new String()" and creates an anonamous instance of the object (in this case a String)? Or is there something else happening here?
If at first you don't succeed, try, try again. If you don't try you have failed.