• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dereferenced??

 
John Swain
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello, i am trying to allow a user to enter 3 characters from a menu A, S, and L. the program works fine. but my question is when i tried to place if (ch.equalsIgnorCase('A'))

{//diplsay message from selecting 'A' from menu.
System.out.println("Add a person");
}
to the program so that it didnt matter if the y used upper case or not i get the error message:
lowChartA.java [24:1] char cannot be dereferenced
if (ch.equalsIgnorCase('A'))
^
not sure what to do here.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Primitive" types, like byte, char, short, int, long, float, double, and boolean, don't have members or methods and so can't be "dereferenced". (To dereference X just means to write X.something .) You can use the various built-in operators to operate on chars, though. To see if a character is an upper or lower-case A, you would write

if (ch == 'a' || ch == 'A') { ...
 
Garry Meax
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hope this help you.

 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The equalsIgnoreCase() method can only be used on Strings, not on chars. To compare chars, you follow EFH's suggestions above. One nice thing about chars is that you can use them in a switch statement, but you cannot use switch with Strings. For example:


Layne
[ February 23, 2005: Message edited by: Layne Lund ]
 
roses are red, violets are blue. Some poems rhyme and some are a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic