Skip Top Navigation Bar

Introduction to String Indexing

String Indexing

Each character of a String literal has an associated index, or label, with the first character being index 0 and each subsequent index is one more than the last. Consider the following example.

char charAt(int index)

This method returns the char value at the specified index.

Your Turn

Let's try it in the Java Playground.

int indexOf(String str)

This method returns

Your Turn

Let's try it in the Java Playground.

There are multiple indexOf methods that take different parameters, some specifying the range of indexes where str is being searched.

Complete List of String Learn Tutorials

Resources

Next Learn Tutorial