java.lang.StringBuffer codePointBefore(int index)

Description :

This java tutorial shows how to use the codePointBefore(int index) method of StringBuffer class under java.lang package.

The codePointBefore(int index) 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().

Method Syntax :

public int codePointBefore(int index)

Parameter Input :

DataType Parameter Description
int index the index following the code point that we are interested

Method Returns :

The codePointBefore(int index) method simply returns the Unicode code point value before the given index.

Compatibility Version :

Requires Java 1.5 and up

Java Code Example :

This java example source code demonstrates the use of codePointBefore(int index) method of StringBuffer class. Initially the code assigns a string “javatutorialhq.com” as initial contents of the string buffer. Then we use the codePointBefore(int index) of the StringBuffer at index 5.

package com.javatutorialhq.java.examples;

/*
 * This example source code demonstrates the use of codePointBefore(int index) 
 * method of StringBuffer class
 */

public class StringBufferCodePointBefore {

	public static void main(String[] args) {

		// initialize the StringBuffer object
		StringBuffer sb = new StringBuffer("javatutorialhq.com");
		System.out.println("Contents of buffer:" + sb);

		// get the codePointBefore on index 5
		int index = 5;
		System.out.println("CodepointBefore on index " + index + " is "
				+ sb.codePointBefore(index));

	}
}

Sample Output :

Running the codePointBefore(int index) method example source code of StringBuffer class will give you the following output

Contents of buffer:javatutorialhq.com
CodepointBefore on index 5 is 116

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :