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 BufferedReader issue? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "BufferedReader issue?" Watch "BufferedReader issue?" New topic

BufferedReader issue?

John Uhlig

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:
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.

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="" target="_blank" rel="nofollow">Java forums using Java software</a> - Come and help get them started.
John Uhlig

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

I agree. Here's the link:
subject: BufferedReader issue?
It's not a secret anymore!