charAt() StringBuffer Example

charAt() StringBuffer Example


To manipulate string, java.lang.StringBuffer class comes with many methods, otherwise which will take long laborious coding as in C/C++. One such method is charAt() StringBuffer that returns the character at the specified index number passed as argument to the method.

What Java API says about charAt() StringBuffer:

  • public synchronized char charAt(int index): Returns the character present at the specified index number in the string buffer. Negative index throws StringIndexOutOfBoundsException.
Following charAt() StringBuffer example illustrates.


charAt() StringBuffer
Output screenshot on charAt() StringBuffer Example

Giving index number greater than the length of the buffer (number of characters present in the buffer) throws StringIndexOutOfBoundsException.

Pass your comments and suggestions on this tutorial "charAt() StringBuffer Example".

Leave a Reply

Your email address will not be published. Required fields are marked *