StringBuilder codePointBefore() in Java with Examples Last Updated : 28 Dec, 2022 Comments Improve Suggest changes Like Article Like Report The codePointBefore() method of StringBuilder class takes an index as a parameter and returns the "Unicode number" of the character before the specified index in String contained by StringBuilder. The index refers to char values (Unicode code units) and 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 (index - 2) is not negative with value is in the high-surrogate range, then the supplementary code point value of the surrogate pair is returned by method. If the char value at index - 1 is an unpaired low-surrogate or a high-surrogate, the surrogate value is returned. Syntax: public int codePointBefore(int index) Parameters: This method accepts one int type parameter index represents index of the character following the character whose unicode value to be returned. Return Value: This method returns "unicode number" of the character before the given index. Exception: This method throws IndexOutOfBoundsException when index is negative or greater than or equal to length(). Below programs demonstrate the codePointBefore() method of StringBuilder Class: Example 1: Java // Java program to demonstrate // the codePointBefore() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("WelcomeGeeks"); // print string System.out.println("String is " + str.toString()); // get unicode of char at index 1 // using codePointBefore() method int unicode = str.codePointBefore(2); // print char and Unicode System.out.println("Unicode of character" + " at position 1 = " + unicode); // get unicode of char at index 10 // using codePointBefore() method unicode = str.codePointBefore(11); // print char and Unicode System.out.println("Unicode of character" + " at position 10 = " + unicode); } } Output:String is WelcomeGeeks Unicode of character at position 1 = 101 Unicode of character at position 10 = 107 Example 2: To demonstrate IndexOutOfBoundsException Java // Java program to demonstrate // exception thrown by codePointBefore() Method. class GFG { public static void main(String[] args) { // create a StringBuilder object // with a String pass as parameter StringBuilder str = new StringBuilder("WelcomeGeeks"); try { // get unicode of char at position length + 2 int unicode = str.codePointBefore( str.length() + 2); } catch (Exception e) { System.out.println("Exception: " + e); } } } Output:Exception: java.lang.StringIndexOutOfBoundsException: String index out of range: 14 Reference: https://docs.oracle.com/javase/10/docs/api/java/lang/StringBuilder.html#codePointBefore(int) Comment More infoAdvertise with us Next Article StringBuilder codePointBefore() in Java with Examples A AmanSingh2210 Follow Improve Article Tags : Java java-basics Java-Functions Java-StringBuilder Practice Tags : Java Similar Reads 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 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 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 StringBuilder delete() in Java with Examples The delete(int start, int end) method of StringBuilder class removes the characters starting from index start to index end-1 from String contained by StringBuilder. This method takes two indexes as a parameter first start represents index of the first character and endIndex represents index after th 3 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 StringBuilder deleteCharAt() in Java with Examples The deleteCharAt(int index) method of StringBuilder class remove the character at the given index from String contained by StringBuilder. This method takes index as a parameter which represents the index of char we want to remove and returns the remaining String as StringBuilder Object. This StringB 3 min read StringBuilder charAt() in Java with Examples The charAt(int index) method of StringBuilder Class is used to return the character at the specified index of String contained by StringBuilder Object. The index value should lie between 0 and length()-1. Syntax: public char charAt(int index) Parameters: This method accepts one int type parameter in 3 min read 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 codePointCount() method in Java with Examples 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 3 min read StringBuilder ensureCapacity() in Java with Examples The ensureCapacity(int minimumCapacity) method of StringBuilder class helps us to ensures the capacity is at least equal to the specified minimumCapacity passed as the parameter to the method. If the current capacity of StringBuilder is less than the argument minimumCapacity, then a new internal arr 2 min read Like