File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why i can Watch "why i can New topic

why i can't compare between streams ??


Joined: Sep 27, 2001
Posts: 4
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)
Cindy Glass
"The Hood"

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.

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

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.
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:
subject: why i can't compare between streams ??
It's not a secret anymore!