i know java API function charAt for example
String s="dato"
char r=s.charAt(0); r is equal d
but my question is how realy it works or what function can i use instead of charAt function to get same result? thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
To what purpose? I mean, if
charAt(0)does what you want, why look for something else?But, to answer your question: no, there is no (reasonably straight forward) way to get the nth character from a String in Java. You could use
String‘ssubstring(...)method, but that returns aString, not achar.Or first convert your
Stringinto an array ofchar‘s withString‘stoCharArray()and get a character from the array, but that’s just silly when you havecharAt(...)at your disposal.