Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > BOOK: Beginning Java 2, JDK 5 Edition
|
BOOK: Beginning Java 2, JDK 5 Edition
This is the forum to discuss the Wrox book Ivor Horton's Beginning Java 2, JDK 5 Edition by Ivor Horton; ISBN: 9780764568749
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Java 2, JDK 5 Edition section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2006, 08:52 PM
Registered User
 
Join Date: Feb 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
Troubles with Programm AlisaSmi Excel VBA 0 March 7th, 2007 07:50 AM
Collection-based for loop syntax question. drosenbaum BOOK: Beginning Java 2, JDK 5 Edition 0 March 5th, 2007 07:19 PM
Database troubles notrosh ASP.NET 2.0 Professional 0 June 13th, 2006 01:20 PM
DataGrid Troubles mrideout BOOK: Beginning ASP.NET 1.0 1 August 17th, 2004 11:32 AM
Interop Troubles Yehuda Pro VB.NET 2002/2003 0 June 29th, 2004 01:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.