Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

java
string
codepointat
communitycreator

What is the String.codePointAt() method in Java?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The codePointAt() method in Java is used to get the Unicode value of a character in the string at the specified index.

Syntax

The codePointAt() method can be declared as shown in the code snippet below:

public int codePointAt(int ind)

Parameters

  • ind: The index of the character whose Unicode value is required. The index value must be between 0 and the length of the string, which in this case is negative one.

Return value

The codePointAt() method returns an int, which is the Unicode value of the specified character.

The codePointAt() method throws the IndexOutOfBoundsException if:

  • The index ind is negative.
  • The index ind is greater than the length of the string.

Code

Consider the code snippet below, which demonstrates the use of the codePointAt() method.

class Main {
public static void main(String[] args)
{
String str = "Hello world!";
int code = str.codePointAt(3);
System.out.println("Code point at 3rd index: " + code);
}
}

Explanation

A string str is declared in line 5. The codePointAt() method is used in line 6 to get the Unicode value of the character at the third index in str.

RELATED TAGS

java
string
codepointat
communitycreator

CONTRIBUTOR

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring