setCharAt() method sets the character at the specified index to ch. This sequence is altered to represent a new character sequence that is identical to the old character sequence, except that it contains the character ch at position index.
The setCharAt(int index, char ch) method of Java StringBuffer class is used to set the specified character at the given index. The specified character altered this sequence by replacing the old character at the given index.
We can convert a char to a string object in java by using the Character. toString() method.
Is there a way to use str.charAt(index) to replace a specific char by index? Something like this:
str.setCharAt(1,'X'); // replace 2nd char with 'X'
Is there any easy way to do that?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With