java.lang.StringBuffer offsetByCodePoints(int index,int codePointOffset)

Description :

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

The offsetByCodePoints(int index,int codePointOffset) returns the index within this sequence that is offset from the given index by codePointOffset code points.

Method Syntax :

public int offsetByCodePoints(int index,int codePointOffset)

Parameter Input :

DataType Parameter Description
int index index to be offset
int codePointOffset offset in code points

Method Returns :

This method simply returns the index within this sequence stored on the buffer.

Compatibility Version :

Requires Java 1.5 and up

Java Code Example :

This java example source code demonstrates the use of offsetByCodePoints(int index,int codePointOffset) method of StringBuffer class. Initially the code assigns a string “javatutorialhq.com” as initial contents of the string buffer. Then we use offsetByCodePoints method with method argument of index as 2 and codepointoffset of 5.

package com.javatutorialhq.java.examples;

/*
 * This example source code demonstrates the use of 
 * offsetByCodePoints method of StringBuffer class
 */

public class StringBufferOffsetByCodePoints {

	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 offsetByCodePoints on index of 2 and an offset of 5
		int index = 2;
		int codePointOffset = 5;

		System.out.println("Result :"
				+ sb.offsetByCodePoints(index, codePointOffset));

	}
}

Sample Output :

Running the above example source code will give the following output

Java StringBuffer offsetByCodePoints() method example

Java StringBuffer offsetByCodePoints() method example

Exception Scenario :

N/A

Similar Method :

  • N/A

Suggested Reading List :

References :