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 replace() in Java with Examples - GeeksforGeeks StringBuilder replace() in Java with ExamplesLast Updated : 24 Jan, 2026 The replace(int start, int end, String str) method of StringBuilder is used to replace a specified range of characters with a given string. It modifies the existing StringBuilder object directly, making it efficient for frequent updates to strings.
Output Hello Java Explanation:
Syntax
Parameters: This method accepts three parameters:
Return Value: This method returns StringBuilder object after successful replacement of characters. Note:
Examples of StringBuilder replace() MethodExample 1: Basic Replacement
Output Original: WelcomeGeeks After: We are Geeks Explanation: Characters from index 1 to 6 are replaced with "e are ". Example 2: Replacing a Substring in the Middle
Output I like Java Explanation: The replace(7, 13, "Java") call replaces the substring "Python" with "Java" in the middle of the StringBuilder. Example 3: Inserting Using replace()
Output Java Programming Explanation: When start and end are the same, the string is inserted at that position. Example 4: Replacing Entire String
Output New Value
Example 5: Invalid Index Handling
Output:
Explanation: The end index exceeds the length of the StringBuilder. 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. |