Originally Posted by xdrechsler
Well, for informational purposes, using the last value of temp (JAVECJAVA), the method indexOf("JAVA") would return 5 I believe. Because that is the index of the start of the word JAVA in JAVECJAVA.
Indexes of Strings are one the most important thing to learn. It took me a while to figure out how string indexing worked so here is how I figured it out.
For this, think of the first row as the String and the second row and the indexes indicating the spaces between the letters (sorry about spacing, couldnt get the forum to post multiple spaces correctly).
. J A V E C J A V A
0 1 2 3 4 5 6 7 8 9
So if you called String.substring(3,6), which returns the string of the indexes between the selected ranges, you would get ECJ
. And if we called String.substring(5,9) (or String.substring(5) if you want from the index to the end) you would receive JAVA
Understanding the substring method and the indexing of strings is vital to understanding how to scan through a string or to cut off parts of strings.