aspose file tools*
The moose likes Beginning Java and the fly likes please explain the following method, please Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please explain the following method, please" Watch "please explain the following method, please" New topic
Author

please explain the following method, please

tim hunt
Greenhorn

Joined: Apr 19, 2001
Posts: 9
private void skipDelimiters() {
while (!retTokens &&
(currentPosition < maxPosition) &&<br /> (delimiters.indexOf(str.charAt(currentPosition)) >= 0)) {
currentPosition++;
}
}

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
Art Metzer
Ranch Hand

Joined: Oct 31, 2000
Posts: 241
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 String indexOf 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).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please explain the following method, please