Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

.lastIndexOf

 
Tim Holmes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to undestand what is going on here:



I know that it is starting at index 10 and figured out that is zero based so it is starting at the "n" of the second "One". Then it counts backwards to find the the last occurrence of "One". The example I am looking at says it is "9", but if i count backwards like when finding the starting index, the "n" of the second "One" is zero and 9 is the "n" of the first "One". Right?
 
Henry Wong
author
Marshal
Pie
Posts: 21391
84
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but if i count backwards like when finding the starting index, the "n" of the second "One" is zero and 9 is the "n" of the first "One". Right?


No. The index of the characters doesn't change -- the index is the index relative from the beginning starting from zero. I don't know about you but it would really be confusion if the index is based on how the method is called.

Henry
 
Tim Holmes
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah that makes sense...thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic