Home » Java programming language

Java StringBuffer int codePointCount(int index1 , int index 2) method with Example

Java StringBuffer int codePointCount(int index1 , int index 2) method: Here, we are going to learn about the int codePointCount(int index1 , int index 2) method of StringBuffer class with its syntax and example.
Submitted by Preeti Jain, on June 29, 2019

StringBuffer Class int codePointCount(int index1 , int index 2)

  • This method is available in package java.lang.StringBuffer.codePointCount(int index).
  • This method is used to return the number of Unicode Codepoint at the specified range of index (i.e. it returns all the number of Unicode codepoint lies between index 1 and index 2) in the method.
  • Index range will start from 0 to length()-1.
  • This method does not raise an exception.

Syntax:

    int codePointCount(int index1 , int index2){
    }

Parameter(s):

We pass two object in the method of the StringBuffer i.e index1 and index2.

Return value:

The return type of this method is int that means this method return the count of all Unicode codepoint lie between index1 and index2 and codepoint value is in number format.

Java program to demonstrate example of codePointCount() method

import java.lang.StringBuffer;

public class StringBufferClass {
    public static void main(String[] args) {

        StringBuffer sb = new StringBuffer("Java is a pure OOPS");

        // use codePointCount(int index1 , int index 2) 
        // it will return the number of  Unicode codepoint lies 
        // between index 1 and index 2
        int codepointcount = sb.codePointCount(2, 8);

        // Display result after implementing codePointCount(2,8)
        System.out.println("The result will be after implementing method codePointCount(2 , 8) is :" + codepointcount);

        sb = new StringBuffer("Current Version of Java is 8");

        // use codePointCount(int index1 , int index2) 
        // it will return the number of Unicode codepoint lies 
        // between index 1 and index 2

        //Display result after implementing codePointCount(3,9)
        System.out.println("The result will be after implementing method codePointCount(3,9) is :" + sb.codePointCount(3, 9));
    }
}

Output

D:\Programs>javac StringBufferClass.java

D:\Programs>java StringBufferClass
The result will be after implementing method codePointCount(2 , 8) is :6
The result will be after implementing method codePointCount(3,9) is :6


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.