Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

charAt() in String

charAt() in String


charAt() has return type char and It gets index number as an argument. 

Suppose we have a string as follows:

String str = "Ankit Shravanekar";

then it's structure will be in the memory as following picture:

 And suppose, we want to get Character 'k' which is situated at the index number '2'. Then, we will call charAt(2) to get character 'k' and we will store this 'k' in a variable of char type as follows:

 char c = str.charAt(2);

Following program shows - By calling charAt(), how we can get desired character from a string.

This post first appeared on BCA MCA NOTES, please read the originial post: here

Share the post

charAt() in String


Subscribe to Bca Mca Notes

Get updates delivered right to your inbox!

Thank you for your subscription