Win a copy of Spark in Action this week in the Open Source Projects forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

How to find the length of a String without using the length method

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
How to find the length of a String without using the length method.Please tell me.Thanks in advance.
 
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to do that? Homework?

Have you looked at the API for java.lang.String? Did nothing occur to you?
 
Shyam Kasthala
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
It was asked in an interview recently?Please give me the answer?Thanks
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and what did you answer in the interview ?
as Peter said: check out the API for java.lang.String

pascal
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
If you do not want to use length() method of string then treat String as array of Character .and use a loop.i think you will be known about it.
regards,
Prashant Kumar Singh
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No need to use a loop if you look at the methods available to String objects.

Personally, if I were asked this in an interview, I'd ask the interviewer in what circumstances you couldn't use the length method of a String. Its a silly question.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of that question probably wasn't to see how well you know the String API, but to see how you react to challenges.
    Bookmark Topic Watch Topic
  • New Topic