aspose file tools*
The moose likes Beginning Java and the fly likes Dereferenced?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Dereferenced??" Watch "Dereferenced??" New topic
Author

Dereferenced??

John Swain
Greenhorn

Joined: Feb 12, 2005
Posts: 16
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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

"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') { ...


[Jess in Action][AskingGoodQuestions]
Garry Meax
Ranch Hand

Joined: Feb 11, 2005
Posts: 31
hope this help you.

Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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 ]

Java API Documentation
The Java Tutorial
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dereferenced??