This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I have taken the above method from the StringTokenizer class and am trying to understand how it works. As I see it the loop breaks only if currentpos is greater than maxposition and if -1 is returned by the indexOf method. This is the bit I dont understand, when does the method return -1? Your help is greatly appreciated. Cheers
Hi, Tim. indexOf is a method of the java.lang.String class. (You can read about it here.) indexOf returns -1 if the char passed as its argument does not appear in the instance of StringindexOf is acting upon. So this bit of StringTokenizer is looping through the String you are tokenizing, starting from an identified position in the String. Flow control depends on whether the character at the identified position is a delimiter for this StringTokenizer. Hope this helps, Art [This message has been edited by Art Metzer (edited June 24, 2001).]