Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (6.5k points)
edited by

Could someone tell me how to find out the character in a String at a given index?

1 Answer

0 votes
by (11.3k points)
edited by

In JAVA, for this, we use the .charAt(int index) function. Basically, what this does is, it takes the index number in the argument that it needs to return the character present in the String. For example, if there is a String:

String ar="abcd";

And the charAt() function is called:

char ch=ar.charAt(1);

This function will return the character present in String ar at index number 1. This implies that the value of ch is 'b' after the execution of that function. 

The most basic JAVA coding mechanisms comprise of these methods so you should have a better understanding of these functions. If you'd like to go over your basics again, you should look into this:

Related questions

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...