Error "Char cannot be dereferenced"

I am trying to use the char isLetter() method, which should return a boolean value corresponding to whether the character is a letter. But when I call the method, I get the message that "char cannot be dereferenced." I don't know what it means to cast a char or how to fix a bug. we are talking about the following:

 if (ch.isLetter()) { .... .... } 

Any help? What does it mean to play char and how can I avoid it?

+7
source share
4 answers

Char is a primitive, not an object, so it cannot be dereferenced

Selection is the process of accessing the value referenced by a link. Since char is already a value (not a reference), it cannot be dereferenced.

use Character class:

 if(Character.isLetter(c)) { 
+18
source

A char has no methods - it is a Java primitive. You are looking for a Character wrapper class.

Usage will be:

 if(Character.isLetter(ch)) { //... } 
+1
source

I think ch declared as char . Since char is a primitive data type and not an object, you cannot call any method from it. You should use Character.isLetter(ch) .

0
source

If Character.isLetter(ch) looks a bit verbose / ugly, you can use static imports.

 import static java.lang.Character.*; if(isLetter(ch)) { } else if(isDigit(ch)) { } 
0
source

All Articles