The
charAt() method is used to get a character at the specified index in the sequence. The index range is [0, length of the sequence - 1].Syntax of charAt() method: public char charAt(int index) The setCharAt() method is used to set a character at the specified index. The sequence is identical except that it sets the specified character at the specified index.Syntax of setCharAt() method:public void setCharAt(int index, char ch) Note that setCharAt method alter the characters in the sequence, it does not append characters to the sequence.
Here is an example program implementing these methods:
StringBuffer charAt and setCharAt CODE class CharAtAndSetCharAtDemo OUTPUT 'Happy New Year!' DESCRIPTION Each character in the sequence is obtained using THINGS TO TRY
|