Write a program to get the character (Unicode code point) at the given index within the String


This Java program demonstrates how to use the codePointAt() method of the String class to obtain the Unicode code point of a character in a given string.

The codePointAt() method returns the Unicode code point value of the character at the specified index in the string. The first argument is the index of the character whose Unicode code point value is to be returned.

In this program, the string "Tutor Joes" is assigned to the str variable. The codePointAt() method is called twice to get the Unicode code point values of the characters at index 0 and 6 respectively. The obtained code points are stored in the v1 and v2 variables.

Finally, the System.out.println() method is used to print the character and its Unicode code point value for the characters at index 0 and 6 respectively.

Source Code

public class Unicode_Point
{
	public static void main(String[] args)
	{
		String str = "Tutor Joes";
		System.out.println("Given String : " + str);
		int v1 = str.codePointAt(0);
		int v2 = str.codePointAt(6);
		System.out.println("Character :"+str.charAt(0)+"\nUnicode Point : " + v1);
		System.out.println("Character :"+str.charAt(6)+"\nUnicode Point : " + v2);
	}
}

Output

Given String : Tutor Joes
Character :T
Unicode Point : 84
Character :J
Unicode Point : 74

Example Programs