Skip to Main Content

New to Java

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!

for loop through string array

843785Feb 12 2009 — edited Feb 12 2009
Checked the tutorials, but there's only examples with the for loop with int arrays, not with string arrays. Can't get this to work. I just want to loop through the array, but the following code says "The local variable i may not have been initialized" for some reason.
String [] words = in.split(" ");
			 
			 for(int i; i<words.length; i++){
If I change it in words.length(), it says "Cannot invoke length() on the array type String[]", which sounds quite right.
words.size() doesn't work either ("Cannot invoke size() on the array type String[]").

What would be the correct syntax for just looping through a string array?

thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2009
Added on Feb 12 2009
7 comments
1,420 views