setCharAt( ) method when used with StringBuffer replaces the character with another at the specified index.
StringBuffer object1 = new StringBuffer("man");
object1.setCharAt(1,'e'); -> This will replace the character available at the provided index '1' in the specified string "man" i.e. 'a' with another character 'e'. The resultant string after replacement is "men"
Lets implement this on Eclipse IDE:
1. Create 'setCharAtDemo' class under any project as shown below:
3. Observe that the output is displayed in the console as shown below:
Click here to download the project containing the class file used in this post (You can download this project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
Using 'getChars( )' method with StringBuffer will be explained in the next post.