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 BufferedReader issue? 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 "BufferedReader issue?" Watch "BufferedReader issue?" New topic
Author

BufferedReader issue?

John Uhlig
Greenhorn

Joined: May 12, 2003
Posts: 13
I have written the following code:



menuSelection is a private String member variable.
showMenu () spits out a menu to the console.

When I run the program, I get this:
Main Menu: (enter in either upper or lower case)
AP = Add person
EP = Edit person
DP = Delete person
AT = Add telephone number
ET = Edit telephone number
DT = Delete telephone number
Q = Quit
Enter your choice:
AP
input...AP...
no match

So, it appears that the result of stdin.readLine() is being assigned to the variable menuSelection, since I can print it out. However, I can't figure out why the result of is failing when I clearly typed AP into the console.

Thanks,
John
Scott Dunbar
Ranch Hand

Joined: Sep 23, 2004
Posts: 245


Be careful - this gets alot of folks. You're really asking if the memory address of menuSelection is the same as the memory address that the compiler assigned to your string. You'll want to do something like:



to check if the strings contain the same value.


<a href="http://forums.hotjoe.com/forums/list.page" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
John Uhlig
Greenhorn

Joined: May 12, 2003
Posts: 13
Duh - a String is an object, not a primitive. (slap on forehead)
Thank you Scott.

John
 
jQuery in Action, 2nd edition
 
subject: BufferedReader issue?