• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String Class Method

 
Deepak Chawla
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just want to know the concept of lastIndexOf method, i read Java API, i didn't understand.
int slash = uri.lastIndexOf("/docs/") + 6;
What this will return.
Please help.
 
Jason Menard
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well it depends on what your uri String is. The code is valid so you should have had no problems running it.

When the above is ran, i evaluates to 7, and j evaluates to 13. The value of i is the index for the beginning of the String "/docs/", keeping in mind that the first character of s, which is "/", has an index of 0. As the above String is of length 13, that is indexes 0-12, the value for j, 13, is outside the bounds of the String length. HTH.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic