java.lang.StringBuffer codePointAt(int index)

Description :

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

The codePointAt(int index) returns the character (Unicode code point) at the specified index. The index refers to char values. Make a note that the index ranges from 0 to length() – 1.

Method Syntax :

public int codePointAt(int index)

Parameter Input :

DataType Parameter Description
int index index to the char values

Method Returns :

The codePointAt(int index) method simply returns ode point value of the character at the index.

Compatibility Version :

Requires Java 1.5 and up

Java Code Example :

This java example source code demonstrates the use of codePointAt(int index) method of StringBuffer class. Initially the code assigns a string “java-tutorial” as initial contents of the string buffer. Then we use the codePointAt of the StringBuffer at index 3.

package com.javatutorialhq.java.examples;

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

public class StringBufferCodePointAt {

	public static void main(String[] args) {

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

		// get the codepointat on index 3
		int index = 3;
		System.out.println("CodepointAt index " + index + " is "
				+ sb.codePointAt(index));

	}
}

Sample Output :

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

Contents of buffer:java-tutorial
CodepointAt index 3 is 97

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :