How can I find the length of a String without using the length() method of String class?
How can I find the length of a String without using the length() method
Share
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.
str.toCharArray().lengthshould work.Or how about:
str.lastIndexOf("")Probably even runs in constant time 🙂
Another one
One of the dumbest solutions:
str.split("").length - 1Is this cheating:
new StringBuilder(str).length()? 🙂