Java Interview Question: How to find length of string in java without using length method?

preview_player
Показать описание
Java Interview Question: how to find length of string in java without using length method

~~~Subscribe to this channel, and press bell icon to get some interesting videos on Selenium and Automation:

Follow me on my Facebook Page:

Let's join our Automation community for some amazing knowledge sharing and group discussion on Telegram:

Naveen AutomationLabs Paid Courses:
Java & Selenium:

Java & API +POSTMAN + RestAssured + HttpClient:
Рекомендации по теме
Комментарии
Автор

Sorry for voice in this video, my voice is still getting recovered. It will be fine in next couple of days. Tried my best to prepare a 10 mins video :) Thanks all for your love and support.

naveenautomationlabs
Автор

Thank you for the interesting video. If I may provide a suggestion - the purpose of this question is to see if the candidate understands the fact that String class is a wrapper around an array of chars in memory, and provides many utility methods over this array (such as length). So getting the char array representation and looping over it with a counter is enough and the right output. The other “ways” are not the right ways even though they give the right answer. No one would compile a regex, or catch an exception to get the length of a string; they’re counterintuitive, expensive, and inefficient.

rkodaman
Автор

So good to hear your voice after so long. God bless you 🙏🏻

poojashaw
Автор

Hi Naveen this one workes to : it will return an int (the deference betwen the str length() and 0)

karimmek
Автор

A better question would be "Why would you need to know the length of a string?" One answer may be "To check for zero length". Then the next question would be "How was the string ever allowed to become zero length?" This leads to a much better evaluation of the person's overall approach to coding and level of skill.

MoMadNU
Автор

My online classes will be continued...feeling happy that u recovers fast...😄

mettuanurag
Автор

Welcome back hope you're good now ❤️

mohamedhazeeb
Автор

Welcome back, hope you and everyone around you will recover fast.

karimmek
Автор

Thanks Naveen for wonderful example, can you also throw light which one is best way to use..and and faster in execution..how to do we determine it speed of execution...??

vinitp
Автор

Hi Naveen, don't strain well soon. We will wait for your Rock.

ganeshteradata
Автор

Very nice info, thank you and take care

snehap
Автор

Legend is back !!!
Take care Naveen!!!

mayurkhobragade
Автор

Hey, Naveen sir
what is .length property and how is it written in java please make a video on it

brijeshjagad
Автор

I have a question for u....
When u enter a URL like www.google.com and run the program it displays a blank page what should i do??
how to resolve the issue??

vivek
Автор

I usually ask this question as my last question, to all the candidates whom I select for next round and its strange that 50% people cannot answer this question :(

harshshah
Автор

String st2 = "Naveen";

int count = 0;

char ar2[] = st2.toCharArray();

for (char pg : ar2)
{
count++;
}
System.out.println("Length of string is" + count);

O/p :- Length of string is 6

ggmushorts