StringBuffer codePointCount() method in Java with Examples Last Updated : 30 Jul, 2019 Comments Improve Suggest changes Like Article Like Report The codePointCount() method of StringBuffer class is used to return the number of Unicode code points in the specified range of beginIndex to endIndex of String contained by StringBuffer. This method takes beginIndex and endIndex as a parameter where beginIndex is the index of the first character of the text range and endIndex is index after the last character of the text range. The indexes refer to char values (Unicode code units) and the value of index must be lie between 0 to length-1. The range starts at the beginIndex and end at the char at index endIndex – 1. Thus the length (in chars) of the text range is endIndex-beginIndex. Syntax: public int codePointCount(int beginIndex, int endIndex) Parameters: This method takes two parameters: beginIndex: int value representing index of the first character of the text range. endIndex: int value representing index after the last character of the text range. Return Value: This method returns int value representing the number of Unicode code points in the specified text range. Exception: This method throws IndexOutOfBoundsException if: the beginIndex is less than zero, or endIndex is larger than the length of String, or beginIndex is larger than endIndex. Below programs illustrate the StringBuffer.codePointCount() method: Example 1: Java // Java program to demonstrate // the codePointCount() Method. class GFG { public static void main(String[] args) { // create a StringBuffer object // with a String pass as parameter StringBuffer str = new StringBuffer("Welcome to GeeksforGeeks"); // print string System.out.println("String = " + str.toString()); // returns the codepoint count from index 4 to 10 int codepoints = str.codePointCount(4, 10); System.out.println("No of Unicode code points " + " between index 4 and index 10 = " + +codepoints); } } Output: String = Welcome to GeeksforGeeks No of Unicode code points between index 4 and index 10 = 6 Example 2: Java // Java program to demonstrate // the codePointCount() Method. class GFG { public static void main(String[] args) { // create a StringBuffer object // with a String pass as parameter StringBuffer str = new StringBuffer("GeeksForGeeks contribute"); // print string System.out.println("String = " + str.toString()); // returns the codepoint count // from index 3 to 7 int codepoints = str.codePointCount(13, 17); System.out.println("No of Unicode code points" + " between index 13 and 17 = " + codepoints); } } Output: String = GeeksForGeeks contribute No of Unicode code points between index 13 and 17 = 4 Example 3: To demonstrate IndexOutOfBoundsException Java // Java program to demonstrate // exception thrown by the codePointCount() Method. class GFG { public static void main(String[] args) { // create a StringBuffer object // with a String pass as parameter StringBuffer str = new StringBuffer("GeeksForGeeks"); try { // make beginIndex greater than endIndex int codepoints = str.codePointCount(2, 0); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output: Exception: java.lang.IndexOutOfBoundsException References: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuffer.html#codePointCount(int, int) Comment More infoAdvertise with us Next Article StringBuffer codePointCount() method in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-lang package Java-Functions java-StringBuffer +1 More Practice Tags : Java Similar Reads StringBuffer codePointAt() method in Java with Examples The codePointAt() method of StringBuffer class returns a character Unicode point at that index in sequence contained by StringBuffer. This method returns the âUnicodenumberâ of the character at that index. Value of index must be lie between 0 to length-1. If the char value present at the given index 2 min read StringBuffer codePointBefore() method in Java with Examples The codePointBefore() method of StringBuffer class is a method used to take an index as a parameter and returns the âUnicode numberâ of the character present before that index. The value of index must lie between 0 to length-1. If the char value at (index â 1) is in the low-surrogate range, char at 2 min read StringBuffer appendCodePoint() Method in Java with Examples appendCodePoint() method of StringBuffer class appends the string representation of the codePoint argument to this sequence for which we require pre-requisite knowledge of ASCII table as then only we will be able to perceive output why the specific literal is being appended as there is already an in 3 min read StringBuilder codePointCount() in Java with Examples The codePointCount() method of StringBuilder class returns the number of Unicode code points in the specified text range in String contained by StringBuilder. This method takes two indexes as a parameter- first beginIndex which represents index of the first character of the text range and endIndex w 3 min read StringBuffer delete() Method in Java with Examples The java.lang.StringBuffer.delete() is an inbuilt method in Java which is used to remove or delete the characters in a substring of this sequence. The substring starts at a specified index start_point and extends to the character at the index end_point. Syntax : public StringBuffer delete(int start_ 3 min read Java String codePoint() Method with Examples A Java string consists of a group of characters and each character is associated with a Unicode point value (alias ASCII value). So to get the Unicode point value of a character in a string we will use the codepoint() method. So in order to move further, we need to know what are the associated Unico 4 min read StringBuilder appendCodePoint() method in Java with Examples The appendCodePoint(int codePoint) method of StringBuilder class is the inbuilt method used to append the string representation of the codePoint argument to this sequence. The argument is appended to this StringBuilder content and length of the object is increased by Character.charCount(codePoint). 2 min read StringBuffer deleteCharAt() Method in Java with Examples The Java.lang.StringBuffer.deleteCharAt() is a built-in Java method which removes the char at the specified position in this sequence. So that the sequence is reduced by 1 char. Syntax: public StringBuffer deleteCharAt(int indexpoint) Parameters : The method accepts a single parameter indexpoint of 2 min read StringBuffer append() Method in Java with Examples Pre-requisite: StringBuffer class in Java The java.lang.StringBuffer.append() method is used to append the string representation of some argument to the sequence. There are 13 ways/forms in which the append() method can be used: StringBuffer append(boolean a) :The java.lang.StringBuffer.append(boole 13 min read StringBuilder codePointAt() in Java with Examples The codePointAt(int index) method of StringBuilder class takes an index as a parameter and returns a character unicode point at that index in String contained by StringBuilder or we can say charPointAt() method returns the "unicode number" of the character at that index. The index refers to char val 4 min read Like