Java StringBuilder lastIndexOf() Method
Example
Find the position of the last "o":
StringBuilder sb = new StringBuilder("Hello World");
System.out.println(sb.lastIndexOf("o"));
Definition and Usage
The lastIndexOf() method returns the position of the last occurrence of the specified text. It returns -1 if the text is not found.
Tip: Use indexOf() to find the first occurrence.
Syntax
One of the following:
public int lastIndexOf(String str)
public int lastIndexOf(String str, int fromIndex)
Parameter Values
| Parameter | Description |
|---|---|
| str | Required. The text to search for. |
| fromIndex | Optional. The index to start the search from. The search goes backward from this position. |
Technical Details
| Returns: | An int value, representing the position of the last occurrence, or -1 if it never occurs. |
|---|
Related Pages
Java String lastIndexOf() Method
❮ StringBuilder Methods