indexOf() StringBuffer Example

indexOf() StringBuffer Example

    java.lang.StringBuffer class comes with many helper methods to manipulate string. One of the methods is overloaded indexOf() method used to search for the first occurrence of a string in the buffer.


    Let us see what Java API says about indexOf() StringBuffer:
    • public int indexOf(String searchString): Returns an int value of the index number of first occurrence of searchString in the buffer. Returns -1 if the searchString is not found.
    • public synchronized int indexOf(String searchString, int searchIndex): Returns an int value of the index number of first occurrence of searchString in the buffer where search starts from searchIndex. Returns -1 if the searchString is not found.
    Following indexOf() StringBuffer example illustrates the usage of two overloaded method in all possible ways.


    indexOf() StringBuffer
    Output screenshot on indexOf() StringBuffer example

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

Leave a Reply

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