Collection-based for loop troubles...
I am trying to compile this code from the book using XCode on a Mac with SDK 1.4 (I know that the book is for JDK 5, but I figure that the first 5 chapters or so are going to be basic enough that it won't matter?):
public class StringTokenizing {
public static void main(String[] args) {
String text = "To be or not to be, that is the question.";
String delimiters = "[, .]";
int[] limits = {0, -1};
for(int limit : limits) {
System.out.println("\nAnalysis with limit = " + limit);
String[] tokens = text.split(delimiters, limit);
System.out.println("Number of tokens: " + tokens.length);
for(String token : tokens) {
System.out.println(token);
}
}
}
}
But, just as with EVERY code involving collection-based for loops -- In this case, the "for(int limit : limits)" statement, etc -- the compiler won't do it. The error points to that line and just says "; expected" as if it has no idea what to do with for loops that are not in the for (x ; x ; x) format...
...Grrrr. This is really starting to make it impossible to follow the examples in the book. Can someone help me?
Thanks!
-matt
|