This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes why i can't compare between streams ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why i can Watch "why i can New topic
Author

why i can't compare between streams ??

Roy
Greenhorn

Joined: Sep 27, 2001
Posts: 4
hi...
i used StreamTokenizer to read a one word at a time from a text document.. but however, i am not able to compare the word taken from the document... when i use System.out.println, i see the correct word.. however it does not enter the IF condition..
for e.g.
.
.
StreamTokenizer reader = new StreamTokenizer (bufReader);
while (reader.ttype!= StreamTokenizer.TT_EOF)
{

record = reader.sval;
record = record.toLowerCase();
if (record = "shopping)
{
System.out.println("in");
}
}
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Again Roy,
Please change your name to be compliant with JavaRanch's naming policy.
Your ID should be 2 separate names with more than 1 letter each. We really want this to be a professional forum and would prefer that you use your REAL name.
Thanks,
Cindy

"JavaRanch, where the deer and the Certified play" - David O'Meara
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
You are using == to compare two String Objects. This returns true if and only if both references point to the same String in memory. To check to see if two String Objects contain the same value, you need to use the equals method.
if(record.equals("shopping"))
------------------
I Hope This Helps
Carl Trusiak, SCJP2


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Paul Keohan
Ranch Hand

Joined: Mar 15, 2000
Posts: 411
I don't know if it's a typo but '=' on its own definitely won't work. That's only used for assignment.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why i can't compare between streams ??