Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

problem with valueOf(), converting a char to Character in Java

Tags:

java

character

I'm trying to convert a char to Character before it gets pushed on a stack but get a "cannot find symbol error", I don't see what the problem might be. This is how I pass the char to the stack:

stack.push(valueOf(in));

Where 'in' is a char.

like image 678
Fred Avatar asked Nov 16 '09 09:11

Fred


2 Answers

valueOf is a class method of Character, among others. You can't just call it without a class to hang it off.

What you're really looking for is

Character.valueOf(in) or new Character(in).

like image 105
Carl Smotricz Avatar answered Oct 12 '22 22:10

Carl Smotricz


You are looking for:

stack.push(Character.valueOf(in));
like image 39
rsp Avatar answered Oct 13 '22 00:10

rsp