GeeCON Prague 2014*
The moose likes Java in General and the fly likes How to find the length of a String without using the length method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "How to find the length of a String without using the length method" Watch "How to find the length of a String without using the length method" New topic
Author

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

Shyam Kasthala
Ranch Hand

Joined: Mar 30, 2006
Posts: 48
Hello,
How to find the length of a String without using the length method.Please tell me.Thanks in advance.


Thanks & Regards<br /> Shyam Kasthala<br />ILFS Infotech Limited
Peter Chase
Ranch Hand

Joined: Oct 30, 2001
Posts: 1970
Why do you want to do that? Homework?

Have you looked at the API for java.lang.String? Did nothing occur to you?


Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.
Shyam Kasthala
Ranch Hand

Joined: Mar 30, 2006
Posts: 48
Hello,
It was asked in an interview recently?Please give me the answer?Thanks
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
and what did you answer in the interview ?
as Peter said: check out the API for java.lang.String

pascal
Prashant kumar Singh
Greenhorn

Joined: Nov 04, 2006
Posts: 22
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
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to find the length of a String without using the length method