Java.lang.StringBuilder.codePointBefore() Method
Description
The java.lang.StringBuilder.codePointBefore() method returns the character (Unicode code point) before the specified index. The index refers to char values (Unicode code units) and ranges from 1 to length().
Declaration
Following is the declaration for java.lang.StringBuilder.codePointBefore() method
public int codePointBefore(int index)
Parameters
index -- This is the index following the code point that should be returned.
Return Value
This method returns the Unicode code point value before the given index.
Exception
IndexOutOfBoundsException -- if the index argument is less than 1 or greater than the length of this sequence.
Example
The following example shows the usage of java.lang.StringBuilder.codePointBefore() method.
package com.tutorialspoint;
import java.lang.*;
public class StringBuilderDemo {
public static void main(String[] args) {
StringBuilder str = new StringBuilder("programming");
System.out.println("string = " + str);
// returns the codepoint before index 3
int retval = str.codePointBefore(3);
System.out.println("Character(unicode point) = " + retval);
str = new StringBuilder("amrood admin ");
System.out.println("string = " + str);
// returns the codepoint before index 6
retval = str.codePointBefore(6);
System.out.println("Character(unicode point) = " + retval);
}
}
Let us compile and run the above program, this will produce the following result:
string = programming Character(unicode point) = 111 string = amrood admin Character(unicode point) = 100