Java.lang.StringBuilder.codePointAt() Method


Advertisements


Description

The java.lang.StringBuilder.codePointAt() method returns the character (Unicode code point) at the specified index. The index refers to char values (Unicode code units) and ranges from 0 to length() - 1.

Declaration

Following is the declaration for java.lang.StringBuilder.codePointAt() method

public int codePointAt(int index)

Parameters

  • index -- This is the index to the char values.

Return Value

This method returns the code point value of the character at the index.

Exception

  • IndexOutOfBoundsException -- if the index argument is negative or not less than the length of this sequence.

Example

The following example shows the usage of java.lang.StringBuilder.codePointAt() 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 at index 5
   int retval = str.codePointAt(5);
   System.out.println("Character(unicode point) = " + retval);
    
   str = new StringBuilder("amrood admin ");
   System.out.println("string = " + str);
   // returns the codepoint at index 6 i.e whitespace character
   retval = str.codePointAt(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) = 97
string = amrood admin
Character(unicode point) = 32

java_lang_stringbuilder.htm

Advertisements