Java Character example to get ASCII or unicode value of the previous character using codePointBefore


public static int codePointBefore(char[] a,int index,int start)

Returns the code point preceding the given index of the char array, where only array elements with index greater than or equal to start can be used. If the char value at (index - 1) in the char array is in the low-surrogate range, (index - 2) is not less than start, and the char value at (index - 2) in the char array is in the high-surrogate range, then the supplementary code point corresponding to this surrogate pair is returned. Otherwise, the char value at (index - 1) is returned.


Program:

package com.candidjava;

public class CharacterCodePointBefore
{
public static void main(String[] args)
{
char[] c = new char[] { 'A', 'b', 'C', 'd'};
int index = 3, start = 1;
int res;

res = Character.codePointBefore(c, index, start);
System.out.println("Unicode code point is " + res);
}
}


Output:

Unicode code point is 67


Description:

This method returns the Unicode code point value before the given index.


Parameters:
    a - the char array
    index - the index following the code point that should be returned
    start - the index of the first array element in the char array


Returns:
    the Unicode code point value before the given index.


Throws:
    NullPointerException - if a is null.
    IndexOutOfBoundsException - if the index argument is not greater than the     start argument or is greater than the length of the char array, or if the start     argument is negative or not less than the length of the char array.



Comments


©candidjava.com