Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading strings until empty

Status
Not open for further replies.

math

Programmer
Mar 21, 2001
56
0
0
BE
Hi,

I want to let the user give strings until he wants to stop. He can stop by just giving an empty string... BUT...
my while loop doesn't seem to work??

read String name;
while (name != "") {
...
read strig name;
}

It doesn't work... I think there's an ENTER hidden, because the user has to press enter so, how can I delete the hidden enter or how do I alter my while loop to make this work ?

THANX SO MUCH,
math
 
Hi ;)
try this..

String name = in.readLine(); //this you must have already.

while (!name.equals("")){
// ..do your stuff here..
name = in.readLine();
}

Remember String is an Object
if s and r are two different strings
s==r is a false boolean statement
It is true though that if you do:
s=r;
s==r become true, because they both now refer to the same place in computer memory (the one initialy refered to by s)
Always use s.equals(r) type of method to compare the content of two strings..
good luck!.. ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top