• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

why i can't compare between streams ??  RSS feed

 
Greenhorn
Posts: 4
  • 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");
}
}
 
"The Hood"
Posts: 8521
  • 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
 
Sheriff
Posts: 3341
  • 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
 
Ranch Hand
Posts: 411
  • 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.
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
ScroogeXHTML - small and flexible RTF to HTML converter library
https://coderanch.com/t/710903/ScroogeXHTML-RTF-HTML-XHTML-converter
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!