Iterating Over a String in Java

Опубликовано: 12 Март 2012
на канале: Bethany Petr
12,137
like

Iterating over a String in Java one character at a time using the .length method to control the for loop and the .substring method to extract a single character.

Questions:
1) What is the name of the function created?

2) What does the parameter passed to the function hold?

3) When iterating over the string, why do we start the for loop at 0?

4) Why do we use text.length() instead of 5 in the continuation condition (middle expression) of the for loop?

5) When iterating over the string, why do we stop the for loop BEFORE it hits the length?

6) What does the first parameter passed to the substring method represent?

7) What does the second parameter passed to the substring method represent?

8) What would the second parameter passed to the substring method have to be to extract two letters at a time instead of one letter at a time?