Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please explain the following method, please

 
tim hunt
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic