Google+

147. Using 'setCharAt( )' method with StringBuffer







setCharAt( )  method when used with StringBuffer replaces the character with another at the specified index.

Example:

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:



2. Save and Run the 'setCharAtDemo' class file
3. Observe that the output is displayed in the console as shown below:



Download this project:

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.



No comments: