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 Comparing Strings After Using BufferedReader Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing Strings After Using BufferedReader" Watch "Comparing Strings After Using BufferedReader" New topic

Comparing Strings After Using BufferedReader

Joe Lank

Joined: Jun 08, 2004
Posts: 9
Line 10 is where I seem to have a problem. I want it to evaluate to true. Works fine when I initialize the string to 'test' right before doing the if statement, but not when inputting 'test' from the keyboard.

Or do I just need explicit casting?

PS - Thanks Darin that work great.
[ June 18, 2004: Message edited by: Joe Lank ]
Darin Niard
Ranch Hand

Joined: Jun 08, 2004
Posts: 118
Strings are classes, not primitive types like ints or chars. So, use the equals method.

I'm not sure if the BufferedReader leaves the newline character in or not, so check that out as well.
I agree. Here's the link:
subject: Comparing Strings After Using BufferedReader
Similar Threads
BufferedReader input fails
accept input about patients, write it to a file, display the file's contents
Bug Using BufferedReader and .showInputDialog
problem writing program
Keyboard.Class/Anyone with brains.pt2