The Java String charAt() Method

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr

This is one of the articles from our Java Tutorial for Beginners.


The Java String charAt() Method

charAt(int index) - It returns you the character that corresponds to a specific index number. Keep in mind that index numbers start from zero.

Syntax:

It will make more sense in an example.

Example

If you run this code on your computer, you'll see the following in the console:

The character with index number 0 is: I

The character with index number 5 is: e

The character with index number 9 is: v

 

Commentary:

We assigned the value of index number 0 to the char variable. The character with index number 0 in the variable "sentence" is "I."

We assigned the value of index number 5 to the char variable. The character with index number 5 in the variable "sentence" is "e."

We assigned the value of index number 9 to the char variable. The character with index number 9 in the variable "sentence" is "v."


You can find more articles in our Java Tutorial for Beginners. 

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr

Facebooktwittergoogle_plustumblrFacebooktwittergoogle_plustumblr
Самоучители--узнать детальнее--