Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

BufferedReader issue?

 
John Uhlig
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 245
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
John Uhlig
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Duh - a String is an object, not a primitive. (slap on forehead)
Thank you Scott.

John
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic