More about Strings

This chapter accompanies the previous one. Read it for even more info on Strings.

10. Play with indexOf()


Answer:

6

The first occurrence of the string "a" within the method's string is at index 6.

Play with indexOf()

Play with the following to gain insight into indexOf().

Try searching for the second occurrence of "ant" in the line. Pay attention to spaces.


String line =  ; // Enter a string here between quotes

String target =  ; // Enter a string here between quotes

int location = line.indexOf( target );

location: 


Question 10:

What is the index of the empty string "" ?