• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why i can't compare between streams ??

 
Roy
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8521
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Carl Trusiak
Sheriff
Posts: 3340
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Paul Keohan
Ranch Hand
Posts: 411
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic