• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Dereferenced??

 
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.
 
author and iconoclast
Posts: 24204
44
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') { ...
 
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.

 
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 ]
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic