• 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

String "A" not recognized as character although debugger say that the ascii code is 65  RSS feed

 
Ranch Hand
Posts: 480
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was running this method and the row firstLetter="A" is not recognized as a true condition, so the loop springs to the else condition. Why?

 
Bartender
Posts: 4531
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using == to compare strings does not work the way you might expect. It will compare String references, which is not want you want. Use "A".equals(b) instead. This compares the actual Strings that are being referred to. Note that you could also use b.equals("A") but that will give you a null pointer exception in the event that b is null.
 
Giovanni Montano
Ranch Hand
Posts: 480
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:Using == to compare strings does not work the way you might expect. It will compare String references, which is not want you want. Use "A".equals(b) instead. This compares the actual Strings that are being referred to. Note that you could also use b.equals("A") but that will give you a null pointer exception in the event that b is null.



I see, thank you very much for your help.
I have also a question regarding patterns, can I publish a second OP post or is not the case, and should I post here or in the design patterns forum? Is really a general one about how to find an algorithm without too many if, that is testable.
 
Carey Brown
Bartender
Posts: 4531
50
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Giovanni Montano wrote:I see, thank you very much for your help.
I have also a question regarding patterns, can I publish a second OP post or is not the case, and should I post here or in the design patterns forum? Is really a general one about how to find an algorithm without too many if, that is testable.


You're welcome.

If your next question pertains to this code then continue to add to this thread.
Else If your question is "beginner" level, then create a new thread in the beginner forum.
Else post your question in the design patterns forum.
 
Giovanni Montano
Ranch Hand
Posts: 480
10
Android Open BSD Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Carey Brown wrote:

Giovanni Montano wrote:I see, thank you very much for your help.
I have also a question regarding patterns, can I publish a second OP post or is not the case, and should I post here or in the design patterns forum? Is really a general one about how to find an algorithm without too many if, that is testable.


You're welcome.

If your next question pertains to this code then continue to add to this thread.
Else If your question is "beginner" level, then create a new thread in the beginner forum.
Else post your question in the design patterns forum.



second condition, beginner design pattern, wannabe super Mocker
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!