java.lang.Character codePointAt(char[] a, int index)
Description
Make a note that the codePointAt method of Character class is static thus it should be accessed statically which means the we would be calling this method in this format:
Character.codepointAt(method args)
Non static method is usually called by just declaring method_name(argument) however in this case since the method is static, it should be called by appending the class name as suffix. We will be encountering a compilation problem if we call the java codepointAt()Â method non statically.
Method Syntax
public static int charCount(int codePoint)
Method Argument
| Data Type | Parameter | Description |
|---|---|---|
| char[] | a | the char array |
| int | index | the index to the char values (Unicode code units) in the char array to be converted |
Method Returns
The codePointAt(char[] a, int index) method of Character class returns the Unicode code point at the given index.
Compatibility
Requires Java 1.5 and up
Java Character codePointAt(char[] a, int index) Example
Below is a simple java example on the usage of codePointAt(char[] a, int index) method of Character class.
package com.javatutorialhq.java.examples;
import java.util.Scanner;
/*
* This example source code demonstrates the use of
* codePointAt(CharSequence seq, int index)
* method of Character class.
*/
public class CharacterCodePointAtExample {
public static void main(String[] args) {
// initialize a new CharSequence object
CharSequence cs = "This is a test string";
// Ask for user input
System.out.print("Enter desired index:");
// use scanner to get the user input
Scanner s = new Scanner(System.in);
int index = s.nextInt();
// close the scanner object
s.close();
// get the code point at the given
// index of the CharSequence
int result = Character.codePointAt(cs, index);
System.out.println("Result:"+result);
}
}
Sample Output
Below is the sample output when you run the above example.
![java Character codePointAt(char[] a, int index) example output java Character codePointAt(char[] a, int index) example output](https://javatutorialhq.com/wp-content/uploads/2016/03/java-Character-codePointAtchar-a-int-index-example-output.gif)