BM Balmiki Mandal 06 May 2023 4 views 0 comments Core Java

Get the ASCII Value of a Character in Java

Get the ASCII Value of a Character in Java

In Java, obtaining the ASCII value of a character is as simple as calling the built-in charAt() method on a String object. The charAt() method takes an integer parameter and returns the character at the specified index within the string.

Here is a simple example of how to use the charAt() method to get the ASCII value of a character:

String s = "Hello World!";
char c = s.charAt(0);
int asciiValue = (int) c;
System.out.println("The ASCII value of " + c + " is: " + asciiValue);

This code will print out the following to the console:

The ASCII value of H is: 72

The (int) cast is required in order to convert the character data type to an integer. Once we have the ASCII character code, we can use it for whatever application we need.

0 Comments

No comments yet, Be the first to comment.

Post a Comment

Please sign in to post a comment.

Related Posts

Unlock the Ins and Outs of JavaScript Engines and Runtimes

What is a JavaScript Engine? A JavaScript engine is a program or interpreter which executes JavaScript code....

BM Balmiki Mandal 05 Sep 2023
Implementing HMACSHA256 Algorithm in Java with Key

Introducing HMACSHA256 in Java with Key HMACSHA256 is an authentication algorithm designed to secure data, su...

BM Balmiki Mandal 30 Aug 2023
HMACSHA256 Java Example - Creating Secure Message Authentication

HMACSHA256 Java Example HMACSHA256 is an advanced encryption algorithm that allows developers to create encry...

BM Balmiki Mandal 30 Aug 2023