Name: rmT116609 Date: 02/12/2004 A DESCRIPTION OF THE REQUEST : Scanner could act as an Iterator of String but not as an Iterable of String. Scanner not implements Iterable<String> and thus is not compatible with foreach (enhancement 'for' loop) to iterate over a stream (i.e. a Readable). JUSTIFICATION : I think this feature could simply improve simple text parsing in order to implements by example word count, word filtering etc... EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - Scanner should implement Iterate<String> ACTUAL - Scanner doesn't implement Iterate<String> ---------- BEGIN SOURCE ---------- public class TestScanner { public static void main(String[] args) { final Scanner scanner=Scanner.create(System.in); for(String text:scanner) out.printf("%s\n",text); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : use an intermediary anonymous class like this : public class TestScanner { public static void main(String[] args) { final Scanner scanner=Scanner.create(System.in); Iterable<String> iterable=new Iterable<String>() { public Iterator<String> iterator() { return scanner; } }; for(String text:iterable) out.printf("%s\n",text); } } (Incident Review ID: 238515) ====================================================================== ###@###.### 11/1/04 20:38 GMT
|