GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — StringBuilder substring() method in Java with examples - GeeksforGeeks StringBuilder substring() method in Java with examplesLast Updated : 19 Dec, 2025 The substring() method of the StringBuilder class is used to extract a portion of characters from an existing character sequence and return it as a new String. It always returns a new String object and does not modify the original StringBuilder. Indexing is zero-based, and passing invalid index values results in runtime exceptions. Example.
Output Substring = ForGeeks Explanation: Index 5 points to the character 'F'. All characters from index 5 to the end are returned as a new String. Syntax
Parameter:
Return Type: String Example 1. Extracting a Substring Starting from a Specific Index
Output Substring = ForGeeks Explanation:
Example 2. Extracting a Substring Using Start and End Index
Output For Explanation:
Handling Invalid Index ValuesPassing a negative index or an index greater than the length of the StringBuilder causes a StringIndexOutOfBoundsException at runtime.
Output java.lang.StringIndexOutOfBoundsException: Range [-3, 13) out of bounds for length 13 Explanation: Negative start index is invalid. The method throws "StringIndexOutOfBoundsException" at runtime. Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |