• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to test if a char equals something  RSS feed

 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
having trouble with this clip of code:


Can someone tell me the proper format to find the value of char? Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that word is a String (please be more complete), charAt() is the proper method to find the character at the specified position. Why do you feel that it may not be?

Also, wondering why you are comparing it against the value 1; that's not a printable character. If you are trying to compare it against the character '1', then the expression would be a == '1'.
 
J. Chris Miller
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
If you are trying to compare it against the character '1', then the expression would be a == '1'.


This was the answer to my question. I had forgotten about the ' symbol used for chars.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!