Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Using a Scanner object in a foreach loop

807589Sep 29 2008 — edited Sep 29 2008
Hi,

I am trying to get this code to work:

String numbers = "45 63 123 4 666";
Scanner scan = new Scanner (numbers);
for (String word : scan)
System.out.println(word);

And I am getting the following error from the compiler:

"foreach not applicable to expression types"

I'm not sure why this is causing a problem. Any enlightenment would be greatly appreciated!

Thanks,
Diane Mega
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 27 2008
Added on Sep 29 2008
3 comments
493 views